aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/git_upload_pack.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/http/git_upload_pack.go')
-rw-r--r--clients/http/git_upload_pack.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go
index 6960be1..217e4aa 100644
--- a/clients/http/git_upload_pack.go
+++ b/clients/http/git_upload_pack.go
@@ -15,6 +15,7 @@ type GitUploadPackService struct {
Client *http.Client
endpoint common.Endpoint
+ auth HTTPAuthMethod
}
func NewGitUploadPackService() *GitUploadPackService {
@@ -29,6 +30,18 @@ func (s *GitUploadPackService) Connect(url common.Endpoint) error {
return nil
}
+func (s *GitUploadPackService) ConnectWithAuth(url common.Endpoint, auth common.AuthMethod) error {
+ httpAuth, ok := auth.(HTTPAuthMethod)
+ if !ok {
+ return InvalidAuthMethodErr
+ }
+
+ s.endpoint = url
+ s.auth = httpAuth
+
+ return nil
+}
+
func (s *GitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
url := fmt.Sprintf("%s/info/refs?service=%s", s.endpoint, common.GitUploadPackServiceName)
res, err := s.doRequest("GET", url, nil)
@@ -69,8 +82,10 @@ func (s *GitUploadPackService) doRequest(method, url string, content *strings.Re
}
s.applyHeadersToRequest(req, content)
+ s.applyAuthToRequest(req)
res, err := s.Client.Do(req)
+
if err != nil {
return nil, core.NewUnexpectedError(err)
}
@@ -94,3 +109,11 @@ func (s *GitUploadPackService) applyHeadersToRequest(req *http.Request, content
req.Header.Add("Content-Length", string(content.Len()))
}
}
+
+func (s *GitUploadPackService) applyAuthToRequest(req *http.Request) {
+ if s.auth == nil {
+ return
+ }
+
+ s.auth.setAuth(req)
+}