NewHTTPClient returns new http client with check redirects policy
(config *HTTPOutputConfig)
| 257 | |
| 258 | // NewHTTPClient returns new http client with check redirects policy |
| 259 | func NewHTTPClient(config *HTTPOutputConfig) *HTTPClient { |
| 260 | client := new(HTTPClient) |
| 261 | client.config = config |
| 262 | var transport *http.Transport |
| 263 | client.Client = &http.Client{ |
| 264 | Timeout: client.config.Timeout, |
| 265 | CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 266 | if len(via) >= client.config.RedirectLimit { |
| 267 | Debug(1, fmt.Sprintf("[HTTPCLIENT] maximum output-http-redirects[%d] reached!", client.config.RedirectLimit)) |
| 268 | return http.ErrUseLastResponse |
| 269 | } |
| 270 | lastReq := via[len(via)-1] |
| 271 | resp := req.Response |
| 272 | Debug(2, fmt.Sprintf("[HTTPCLIENT] HTTP redirects from %q to %q with %q", lastReq.Host, req.Host, resp.Status)) |
| 273 | return nil |
| 274 | }, |
| 275 | } |
| 276 | if config.SkipVerify { |
| 277 | // clone to avoid modying global default RoundTripper |
| 278 | transport = http.DefaultTransport.(*http.Transport).Clone() |
| 279 | transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} |
| 280 | client.Client.Transport = transport |
| 281 | } |
| 282 | |
| 283 | return client |
| 284 | } |
| 285 | |
| 286 | // Send sends an http request using client create by NewHTTPClient |
| 287 | func (c *HTTPClient) Send(data []byte) ([]byte, error) { |
no test coverage detected