diff options
Diffstat (limited to 'clients/http')
-rw-r--r-- | clients/http/git_upload_pack.go | 23 | ||||
-rw-r--r-- | clients/http/git_upload_pack_test.go | 22 |
2 files changed, 41 insertions, 4 deletions
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go index 96dbdce..b128c1c 100644 --- a/clients/http/git_upload_pack.go +++ b/clients/http/git_upload_pack.go @@ -1,6 +1,7 @@ package http import ( + "fmt" "io" "net/http" "strings" @@ -28,7 +29,8 @@ func (s *GitUploadPackService) Connect(url common.Endpoint) error { } func (s *GitUploadPackService) Info() (*common.GitUploadPackInfo, error) { - res, err := s.doRequest("GET", common.GitUploadPackServiceName, nil) + url := fmt.Sprintf("%s/info/refs?service=%s", s.endpoint, common.GitUploadPackServiceName) + res, err := s.doRequest("GET", url, nil) if err != nil { return nil, err } @@ -39,13 +41,28 @@ func (s *GitUploadPackService) Info() (*common.GitUploadPackInfo, error) { return common.NewGitUploadPackInfo(dec) } -func (s *GitUploadPackService) doRequest(method, service string, content *strings.Reader) (*http.Response, error) { +func (s *GitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadCloser, error) { + url := fmt.Sprintf("%s/%s", s.endpoint, common.GitUploadPackServiceName) + res, err := s.doRequest("POST", url, r.Reader()) + if err != nil { + return nil, err + } + + h := make([]byte, 8) + if _, err := res.Body.Read(h); err != nil { + return nil, err + } + + return res.Body, nil +} + +func (s *GitUploadPackService) doRequest(method, url string, content *strings.Reader) (*http.Response, error) { var body io.Reader if content != nil { body = content } - req, err := http.NewRequest(method, s.endpoint.Service(service), body) + req, err := http.NewRequest(method, url, body) if err != nil { return nil, err } diff --git a/clients/http/git_upload_pack_test.go b/clients/http/git_upload_pack_test.go index b478445..603cd1b 100644 --- a/clients/http/git_upload_pack_test.go +++ b/clients/http/git_upload_pack_test.go @@ -1,6 +1,11 @@ package http -import . "gopkg.in/check.v1" +import ( + "io/ioutil" + + . "gopkg.in/check.v1" + "gopkg.in/src-d/go-git.v2/clients/common" +) type SuiteRemote struct{} @@ -30,3 +35,18 @@ func (s *SuiteRemote) TestCapabilities(c *C) { c.Assert(err, IsNil) c.Assert(info.Capabilities.Get("agent"), HasLen, 1) } + +func (s *SuiteRemote) TestFetch(c *C) { + r := NewGitUploadPackService() + c.Assert(r.Connect(RepositoryFixture), IsNil) + + reader, err := r.Fetch(&common.GitUploadPackRequest{ + Want: []string{"6ecf0ef2c2dffb796033e5a02219af86ec6584e5"}, + }) + + c.Assert(err, IsNil) + + b, err := ioutil.ReadAll(reader) + c.Assert(err, IsNil) + c.Assert(b, HasLen, 85374) +} |