aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/http/common.go')
-rw-r--r--clients/http/common.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/clients/http/common.go b/clients/http/common.go
index 703208b..483308a 100644
--- a/clients/http/common.go
+++ b/clients/http/common.go
@@ -9,15 +9,18 @@ import (
"gopkg.in/src-d/go-git.v4/core"
)
+// HTTPAuthMethod concrete implementation of common.AuthMethod for HTTP services
type HTTPAuthMethod interface {
common.AuthMethod
setAuth(r *http.Request)
}
+// BasicAuth represent a HTTP basic auth
type BasicAuth struct {
username, password string
}
+// NewBasicAuth returns a BasicAuth base on the given user and password
func NewBasicAuth(username, password string) *BasicAuth {
return &BasicAuth{username, password}
}
@@ -26,6 +29,7 @@ func (a *BasicAuth) setAuth(r *http.Request) {
r.SetBasicAuth(a.username, a.password)
}
+// Name name of the auth
func (a *BasicAuth) Name() string {
return "http-basic-auth"
}
@@ -39,10 +43,12 @@ func (a *BasicAuth) String() string {
return fmt.Sprintf("%s - %s:%s", a.Name(), a.username, masked)
}
+// HTTPError a dedicated error to return errors bases on status codes
type HTTPError struct {
Response *http.Response
}
+// NewHTTPError returns a new HTTPError based on a http response
func NewHTTPError(r *http.Response) error {
if r.StatusCode >= 200 && r.StatusCode < 300 {
return nil
@@ -59,6 +65,7 @@ func NewHTTPError(r *http.Response) error {
return core.NewUnexpectedError(err)
}
+// StatusCode returns the status code of the response
func (e *HTTPError) StatusCode() int {
return e.Response.StatusCode
}