mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Added HTTPAuthDecorator
This commit is contained in:
parent
3ed0ff85f5
commit
bbf9135adc
1 changed files with 22 additions and 0 deletions
|
@ -107,6 +107,23 @@ func (h *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *htt
|
|||
return req, nil
|
||||
}
|
||||
|
||||
type HTTPAuthDecorator struct {
|
||||
login string
|
||||
password string
|
||||
}
|
||||
|
||||
func NewHTTPAuthDecorator(login, password string) HTTPRequestDecorator {
|
||||
ret := new(HTTPAuthDecorator)
|
||||
ret.login = login
|
||||
ret.password = password
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *HTTPAuthDecorator) ChangeRequest(req *http.Request) (*http.Request, error) {
|
||||
req.SetBasicAuth(self.login, self.password)
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// HTTPRequestFactory creates an HTTP request
|
||||
// and applies a list of decorators on the request.
|
||||
type HTTPRequestFactory struct {
|
||||
|
@ -119,6 +136,10 @@ func NewHTTPRequestFactory(d ...HTTPRequestDecorator) *HTTPRequestFactory {
|
|||
}
|
||||
}
|
||||
|
||||
func (self *HTTPRequestFactory) AddDecorator(d... HTTPRequestDecorator) {
|
||||
self.decorators = append(self.decorators, d...)
|
||||
}
|
||||
|
||||
// NewRequest() creates a new *http.Request,
|
||||
// applies all decorators in the HTTPRequestFactory on the request,
|
||||
// then applies decorators provided by d on the request.
|
||||
|
@ -144,5 +165,6 @@ func (h *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader, d
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
Debugf("%v -- HEADERS: %v", req.URL, req.Header)
|
||||
return req, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue