aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http/upload_pack.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-25 14:26:17 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-25 14:26:17 +0200
commitaf3f5e2b9139674b49c5caf0bc06e93cbc426727 (patch)
tree06dbaadba6bbee95afd3212438e2434846312dcc /plumbing/transport/http/upload_pack.go
parent8e83055176bbbbbde206884f10dc238fd378b9b4 (diff)
downloadgo-git-af3f5e2b9139674b49c5caf0bc06e93cbc426727.tar.gz
transport: context package support
Diffstat (limited to 'plumbing/transport/http/upload_pack.go')
-rw-r--r--plumbing/transport/http/upload_pack.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/plumbing/transport/http/upload_pack.go b/plumbing/transport/http/upload_pack.go
index b1181b6..c5ac325 100644
--- a/plumbing/transport/http/upload_pack.go
+++ b/plumbing/transport/http/upload_pack.go
@@ -2,6 +2,7 @@ package http
import (
"bytes"
+ "context"
"fmt"
"io"
"net/http"
@@ -28,7 +29,10 @@ func (s *upSession) AdvertisedReferences() (*packp.AdvRefs, error) {
return advertisedReferences(s.session, transport.UploadPackServiceName)
}
-func (s *upSession) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
+func (s *upSession) UploadPack(
+ ctx context.Context, req *packp.UploadPackRequest,
+) (*packp.UploadPackResponse, error) {
+
if req.IsEmpty() {
return nil, transport.ErrEmptyUploadPackRequest
}
@@ -47,7 +51,7 @@ func (s *upSession) UploadPack(req *packp.UploadPackRequest) (*packp.UploadPackR
return nil, err
}
- res, err := s.doRequest(http.MethodPost, url, content)
+ res, err := s.doRequest(ctx, http.MethodPost, url, content)
if err != nil {
return nil, err
}
@@ -70,7 +74,10 @@ func (s *upSession) Close() error {
return nil
}
-func (s *upSession) doRequest(method, url string, content *bytes.Buffer) (*http.Response, error) {
+func (s *upSession) doRequest(
+ ctx context.Context, method, url string, content *bytes.Buffer,
+) (*http.Response, error) {
+
var body io.Reader
if content != nil {
body = content
@@ -84,7 +91,7 @@ func (s *upSession) doRequest(method, url string, content *bytes.Buffer) (*http.
applyHeadersToRequest(req, content, s.endpoint.Host(), transport.UploadPackServiceName)
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)
}