| ... | ... |
@@ -107,6 +107,23 @@ func (h *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *htt |
| 107 | 107 |
return req, nil |
| 108 | 108 |
} |
| 109 | 109 |
|
| 110 |
+type HTTPAuthDecorator struct {
|
|
| 111 |
+ login string |
|
| 112 |
+ password string |
|
| 113 |
+} |
|
| 114 |
+ |
|
| 115 |
+func NewHTTPAuthDecorator(login, password string) HTTPRequestDecorator {
|
|
| 116 |
+ ret := new(HTTPAuthDecorator) |
|
| 117 |
+ ret.login = login |
|
| 118 |
+ ret.password = password |
|
| 119 |
+ return ret |
|
| 120 |
+} |
|
| 121 |
+ |
|
| 122 |
+func (self *HTTPAuthDecorator) ChangeRequest(req *http.Request) (*http.Request, error) {
|
|
| 123 |
+ req.SetBasicAuth(self.login, self.password) |
|
| 124 |
+ return req, nil |
|
| 125 |
+} |
|
| 126 |
+ |
|
| 110 | 127 |
// HTTPRequestFactory creates an HTTP request |
| 111 | 128 |
// and applies a list of decorators on the request. |
| 112 | 129 |
type HTTPRequestFactory struct {
|
| ... | ... |
@@ -119,6 +136,10 @@ func NewHTTPRequestFactory(d ...HTTPRequestDecorator) *HTTPRequestFactory {
|
| 119 | 119 |
} |
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 |
+func (self *HTTPRequestFactory) AddDecorator(d... HTTPRequestDecorator) {
|
|
| 123 |
+ self.decorators = append(self.decorators, d...) |
|
| 124 |
+} |
|
| 125 |
+ |
|
| 122 | 126 |
// NewRequest() creates a new *http.Request, |
| 123 | 127 |
// applies all decorators in the HTTPRequestFactory on the request, |
| 124 | 128 |
// then applies decorators provided by d on the request. |
| ... | ... |
@@ -144,5 +165,6 @@ func (h *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader, d |
| 144 | 144 |
return nil, err |
| 145 | 145 |
} |
| 146 | 146 |
} |
| 147 |
+ Debugf("%v -- HEADERS: %v", req.URL, req.Header)
|
|
| 147 | 148 |
return req, err |
| 148 | 149 |
} |