aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http/fetch_pack.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-12-06 15:46:09 +0100
committerGitHub <noreply@github.com>2016-12-06 15:46:09 +0100
commit22fe81f342538ae51442a72356036768f7f1a2f9 (patch)
treeccfe9fcd48d3c8f349b42413f71f26ba23a4cba9 /plumbing/transport/http/fetch_pack.go
parent4b5849db76905830e0124b6b9f4294ee13308e0f (diff)
downloadgo-git-22fe81f342538ae51442a72356036768f7f1a2f9.tar.gz
protocol/packp: UploadPackResponse implementation (#161)
* plumbing/protocol: paktp avoid duplication of haves, wants and shallow * protocol/pakp: UploadPackResponse implementation * changes * changes * changes * debug * changes
Diffstat (limited to 'plumbing/transport/http/fetch_pack.go')
-rw-r--r--plumbing/transport/http/fetch_pack.go38
1 files changed, 12 insertions, 26 deletions
diff --git a/plumbing/transport/http/fetch_pack.go b/plumbing/transport/http/fetch_pack.go
index f250667..20cdb55 100644
--- a/plumbing/transport/http/fetch_pack.go
+++ b/plumbing/transport/http/fetch_pack.go
@@ -11,6 +11,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/format/pktline"
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
+ "gopkg.in/src-d/go-git.v4/plumbing/transport/internal/common"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
@@ -74,12 +75,12 @@ func (s *fetchPackSession) AdvertisedReferences() (*packp.AdvRefs, error) {
return ar, nil
}
-func (s *fetchPackSession) FetchPack(r *packp.UploadPackRequest) (io.ReadCloser, error) {
- if r.IsEmpty() {
+func (s *fetchPackSession) FetchPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
+ if req.IsEmpty() {
return nil, transport.ErrEmptyUploadPackRequest
}
- if err := r.Validate(); err != nil {
+ if err := req.Validate(); err != nil {
return nil, err
}
@@ -88,31 +89,27 @@ func (s *fetchPackSession) FetchPack(r *packp.UploadPackRequest) (io.ReadCloser,
s.endpoint.String(), transport.UploadPackServiceName,
)
- content, err := uploadPackRequestToReader(r)
+ content, err := uploadPackRequestToReader(req)
if err != nil {
return nil, err
}
- res, err := s.doRequest("POST", url, content)
+ res, err := s.doRequest(http.MethodPost, url, content)
if err != nil {
return nil, err
}
- reader, err := ioutil.NonEmptyReader(res.Body)
- if err == ioutil.ErrEmptyReader || err == io.ErrUnexpectedEOF {
- return nil, transport.ErrEmptyUploadPackRequest
- }
-
+ r, err := ioutil.NonEmptyReader(res.Body)
if err != nil {
- return nil, err
- }
+ if err == ioutil.ErrEmptyReader || err == io.ErrUnexpectedEOF {
+ return nil, transport.ErrEmptyUploadPackRequest
+ }
- rc := ioutil.NewReadCloser(reader, res.Body)
- if err := discardResponseInfo(rc); err != nil {
return nil, err
}
- return rc, nil
+ rc := ioutil.NewReadCloser(r, res.Body)
+ return common.DecodeUploadPackResponse(rc, req)
}
// Close does nothing.
@@ -120,17 +117,6 @@ func (s *fetchPackSession) Close() error {
return nil
}
-func discardResponseInfo(r io.Reader) error {
- s := pktline.NewScanner(r)
- for s.Scan() {
- if bytes.Equal(s.Bytes(), []byte{'N', 'A', 'K', '\n'}) {
- break
- }
- }
-
- return s.Err()
-}
-
func (s *fetchPackSession) doRequest(method, url string, content *strings.Reader) (*http.Response, error) {
var body io.Reader
if content != nil {