aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http/upload_pack.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-06-16 16:06:32 +0200
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-07-04 11:17:26 +0200
commit06f26e2d7096a7e8458e9e9b41e05c8bb83babf6 (patch)
tree98ae3a8168532ce40c06ef2e6a144c6346c42ef3 /plumbing/transport/http/upload_pack.go
parentce6f5b7c82fc6c2c4d41880ed6b26f921dd9c1c3 (diff)
downloadgo-git-06f26e2d7096a7e8458e9e9b41e05c8bb83babf6.tar.gz
transport: http push
Diffstat (limited to 'plumbing/transport/http/upload_pack.go')
-rw-r--r--plumbing/transport/http/upload_pack.go73
1 files changed, 4 insertions, 69 deletions
diff --git a/plumbing/transport/http/upload_pack.go b/plumbing/transport/http/upload_pack.go
index 2d1ea45..b1181b6 100644
--- a/plumbing/transport/http/upload_pack.go
+++ b/plumbing/transport/http/upload_pack.go
@@ -5,7 +5,6 @@ import (
"fmt"
"io"
"net/http"
- "strconv"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/pktline"
@@ -20,62 +19,13 @@ type upSession struct {
}
func newUploadPackSession(c *http.Client, ep transport.Endpoint, auth transport.AuthMethod) (transport.UploadPackSession, error) {
- s := &session{
- auth: basicAuthFromEndpoint(ep),
- client: c,
- endpoint: ep,
- }
- if auth != nil {
- a, ok := auth.(AuthMethod)
- if !ok {
- return nil, transport.ErrInvalidAuthMethod
- }
+ s, err := newSession(c, ep, auth)
- s.auth = a
- }
-
- return &upSession{session: s}, nil
+ return &upSession{s}, err
}
func (s *upSession) AdvertisedReferences() (*packp.AdvRefs, error) {
- if s.advRefs != nil {
- return s.advRefs, nil
- }
-
- url := fmt.Sprintf(
- "%s/info/refs?service=%s",
- s.endpoint.String(), transport.UploadPackServiceName,
- )
-
- req, err := http.NewRequest(http.MethodGet, url, nil)
- if err != nil {
- return nil, err
- }
-
- s.applyAuthToRequest(req)
- s.applyHeadersToRequest(req, nil)
- res, err := s.client.Do(req)
- if err != nil {
- return nil, err
- }
-
- if err := NewErr(res); err != nil {
- _ = res.Body.Close()
- return nil, err
- }
-
- ar := packp.NewAdvRefs()
- if err := ar.Decode(res.Body); err != nil {
- if err == packp.ErrEmptyAdvRefs {
- err = transport.ErrEmptyRemoteRepository
- }
-
- return nil, err
- }
-
- transport.FilterUnsupportedCapabilities(ar.Capabilities)
- s.advRefs = ar
- return ar, nil
+ return advertisedReferences(s.session, transport.UploadPackServiceName)
}
func (s *upSession) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
@@ -131,7 +81,7 @@ func (s *upSession) doRequest(method, url string, content *bytes.Buffer) (*http.
return nil, plumbing.NewPermanentError(err)
}
- s.applyHeadersToRequest(req, content)
+ applyHeadersToRequest(req, content, s.endpoint.Host(), transport.UploadPackServiceName)
s.applyAuthToRequest(req)
res, err := s.client.Do(req)
@@ -147,21 +97,6 @@ func (s *upSession) doRequest(method, url string, content *bytes.Buffer) (*http.
return res, nil
}
-// it requires a bytes.Buffer, because we need to know the length
-func (s *upSession) applyHeadersToRequest(req *http.Request, content *bytes.Buffer) {
- req.Header.Add("User-Agent", "git/1.0")
- req.Header.Add("Host", s.endpoint.Host()) // host:port
-
- if content == nil {
- req.Header.Add("Accept", "*/*")
- return
- }
-
- req.Header.Add("Accept", "application/x-git-upload-pack-result")
- req.Header.Add("Content-Type", "application/x-git-upload-pack-request")
- req.Header.Add("Content-Length", strconv.Itoa(content.Len()))
-}
-
func uploadPackRequestToReader(req *packp.UploadPackRequest) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
e := pktline.NewEncoder(buf)