aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/git_upload_pack.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-25 15:10:40 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-25 15:10:40 +0200
commit0f97041639b55bc4631145e2053a47a1eb8cdef0 (patch)
tree07de52218d3c0e69994c2614f7875af2635ae682 /clients/http/git_upload_pack.go
parent0fa6f26b0e6ca242088794027c0a32d01e1bc6f9 (diff)
downloadgo-git-0f97041639b55bc4631145e2053a47a1eb8cdef0.tar.gz
clients/http: better error handling
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()
+}