aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/git_upload_pack.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/http/git_upload_pack.go')
-rw-r--r--clients/http/git_upload_pack.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go
index 79aec3f..bca4534 100644
--- a/clients/http/git_upload_pack.go
+++ b/clients/http/git_upload_pack.go
@@ -1,6 +1,7 @@
package http
import (
+ "bufio"
"fmt"
"io"
"net/http"
@@ -66,11 +67,20 @@ func (s *GitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadClo
return nil, err
}
- if err := s.discardResponseInfo(res.Body); err != nil {
+ reader := newBufferedReadCloser(res.Body)
+ if _, err := reader.Peek(1); err != nil {
+ if err == io.ErrUnexpectedEOF {
+ return nil, common.ErrEmptyGitUploadPack
+ }
+
+ return nil, err
+ }
+
+ if err := s.discardResponseInfo(reader); err != nil {
return nil, err
}
- return res.Body, nil
+ return reader, nil
}
func (s *GitUploadPackService) discardResponseInfo(r io.Reader) error {
@@ -138,3 +148,16 @@ func (s *GitUploadPackService) applyAuthToRequest(req *http.Request) {
func (s *GitUploadPackService) Disconnect() (err error) {
return nil
}
+
+type bufferedReadCloser struct {
+ *bufio.Reader
+ closer io.Closer
+}
+
+func newBufferedReadCloser(r io.ReadCloser) *bufferedReadCloser {
+ return &bufferedReadCloser{bufio.NewReader(r), r}
+}
+
+func (r *bufferedReadCloser) Close() error {
+ return r.closer.Close()
+}