From e1d8866ffa78fa16d2f39b0ba5344a7269ee5371 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Fri, 23 Oct 2015 02:26:15 +0200 Subject: clients and remote: fetch implementation --- clients/http/git_upload_pack.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'clients/http/git_upload_pack.go') 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 } -- cgit