aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/client/http/git_upload_pack.go
diff options
context:
space:
mode:
authorferhat elmas <elmas.ferhat@gmail.com>2016-11-15 01:18:53 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-15 01:18:53 +0100
commit16d86605732ba3198c0acd4317b53cf4991a7d4d (patch)
tree3306f0438235f7dfe19fd37c5393a4794abe0535 /plumbing/client/http/git_upload_pack.go
parenteb89d2dd9a36440d58aea224c055b364e49785f7 (diff)
downloadgo-git-16d86605732ba3198c0acd4317b53cf4991a7d4d.tar.gz
Add configurable http client factory (fixes #120) (#121)
* new http client factory ready to install/override default http(s) * mv GitUploadPackServiceFactory to clients.common pkg * rename http.HTTPError to http.Err * rename http.HTTPAuthMethod to http.AuthMethod * add doc and examples/ usage * general improvements: - update install link in readme to v4 (example are already pointing v4) - fix indentation in package doc (styling for godoc.org) - use http.Status constants instead of integers - close leaked response body - rm named returns which stutter in doc - fix one format string - rm unnecessary if checks - documentation fixes
Diffstat (limited to 'plumbing/client/http/git_upload_pack.go')
-rw-r--r--plumbing/client/http/git_upload_pack.go32
1 files changed, 24 insertions, 8 deletions
diff --git a/plumbing/client/http/git_upload_pack.go b/plumbing/client/http/git_upload_pack.go
index c1f4a0b..1ecf299 100644
--- a/plumbing/client/http/git_upload_pack.go
+++ b/plumbing/client/http/git_upload_pack.go
@@ -13,26 +13,41 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/format/packp/pktline"
)
-// GitUploadPackService git-upoad-pack service over HTTP
+// GitUploadPackService git-upload-pack service over HTTP
type GitUploadPackService struct {
client *http.Client
endpoint common.Endpoint
- auth HTTPAuthMethod
+ auth AuthMethod
}
// NewGitUploadPackService connects to a git-upload-pack service over HTTP, the
// auth is extracted from the URL, or can be provided using the SetAuth method
func NewGitUploadPackService(endpoint common.Endpoint) common.GitUploadPackService {
+ return newGitUploadPackService(endpoint, http.DefaultClient)
+}
+
+// NewGitUploadPackServiceFactory creates a http client factory with a customizable client
+// See `InstallProtocol` to install and override default http client.
+// Unless a properly initialized client is given, it will fall back into `http.DefaultClient`.
+func NewGitUploadPackServiceFactory(client *http.Client) common.GitUploadPackServiceFactory {
+ return func(endpoint common.Endpoint) common.GitUploadPackService {
+ return newGitUploadPackService(endpoint, client)
+ }
+}
+
+func newGitUploadPackService(endpoint common.Endpoint, client *http.Client) common.GitUploadPackService {
+ if client == nil {
+ client = http.DefaultClient
+ }
s := &GitUploadPackService{
- client: http.DefaultClient,
+ client: client,
endpoint: endpoint,
}
-
s.setBasicAuthFromEndpoint()
return s
}
-// Connect has not any effect, is here just for meet the interface
+// Connect has not any effect, is here to satisfy interface
func (s *GitUploadPackService) Connect() error {
return nil
}
@@ -54,7 +69,7 @@ func (s *GitUploadPackService) setBasicAuthFromEndpoint() {
// SetAuth sets the AuthMethod
func (s *GitUploadPackService) SetAuth(auth common.AuthMethod) error {
- httpAuth, ok := auth.(HTTPAuthMethod)
+ httpAuth, ok := auth.(AuthMethod)
if !ok {
return common.ErrInvalidAuthMethod
}
@@ -139,7 +154,8 @@ func (s *GitUploadPackService) doRequest(method, url string, content *strings.Re
return nil, plumbing.NewUnexpectedError(err)
}
- if err := NewHTTPError(res); err != nil {
+ if err := NewErr(res); err != nil {
+ _ = res.Body.Close()
return nil, err
}
@@ -168,7 +184,7 @@ func (s *GitUploadPackService) applyAuthToRequest(req *http.Request) {
}
// Disconnect do nothing
-func (s *GitUploadPackService) Disconnect() (err error) {
+func (s *GitUploadPackService) Disconnect() error {
return nil
}