diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-25 14:26:17 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-25 14:26:17 +0200 |
commit | af3f5e2b9139674b49c5caf0bc06e93cbc426727 (patch) | |
tree | 06dbaadba6bbee95afd3212438e2434846312dcc /plumbing/transport/http/receive_pack.go | |
parent | 8e83055176bbbbbde206884f10dc238fd378b9b4 (diff) | |
download | go-git-af3f5e2b9139674b49c5caf0bc06e93cbc426727.tar.gz |
transport: context package support
Diffstat (limited to 'plumbing/transport/http/receive_pack.go')
-rw-r--r-- | plumbing/transport/http/receive_pack.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/plumbing/transport/http/receive_pack.go b/plumbing/transport/http/receive_pack.go index b8489a7..b54b70f 100644 --- a/plumbing/transport/http/receive_pack.go +++ b/plumbing/transport/http/receive_pack.go @@ -2,6 +2,7 @@ package http import ( "bytes" + "context" "fmt" "io" "net/http" @@ -25,7 +26,7 @@ func (s *rpSession) AdvertisedReferences() (*packp.AdvRefs, error) { return advertisedReferences(s.session, transport.ReceivePackServiceName) } -func (s *rpSession) ReceivePack(req *packp.ReferenceUpdateRequest) ( +func (s *rpSession) ReceivePack(ctx context.Context, req *packp.ReferenceUpdateRequest) ( *packp.ReportStatus, error) { url := fmt.Sprintf( "%s/%s", @@ -37,7 +38,7 @@ func (s *rpSession) ReceivePack(req *packp.ReferenceUpdateRequest) ( return nil, err } - res, err := s.doRequest(http.MethodPost, url, buf) + res, err := s.doRequest(ctx, http.MethodPost, url, buf) if err != nil { return nil, err } @@ -61,7 +62,10 @@ func (s *rpSession) ReceivePack(req *packp.ReferenceUpdateRequest) ( return report, report.Error() } -func (s *rpSession) doRequest(method, url string, content *bytes.Buffer) (*http.Response, error) { +func (s *rpSession) doRequest( + ctx context.Context, method, url string, content *bytes.Buffer, +) (*http.Response, error) { + var body io.Reader if content != nil { body = content @@ -75,7 +79,7 @@ func (s *rpSession) doRequest(method, url string, content *bytes.Buffer) (*http. applyHeadersToRequest(req, content, s.endpoint.Host(), transport.ReceivePackServiceName) s.applyAuthToRequest(req) - res, err := s.client.Do(req) + res, err := s.client.Do(req.WithContext(ctx)) if err != nil { return nil, plumbing.NewUnexpectedError(err) } |