aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/transport/http')
-rw-r--r--plumbing/transport/http/receive_pack.go12
-rw-r--r--plumbing/transport/http/upload_pack.go15
2 files changed, 19 insertions, 8 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)
}
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)
}