MCPcopy
hub / github.com/probelabs/goreplay / NewHTTPClient

Function NewHTTPClient

output_http.go:259–284  ·  view source on GitHub ↗

NewHTTPClient returns new http client with check redirects policy

(config *HTTPOutputConfig)

Source from the content-addressed store, hash-verified

257
258// NewHTTPClient returns new http client with check redirects policy
259func 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
287func (c *HTTPClient) Send(data []byte) ([]byte, error) {

Callers 1

NewHTTPOutputFunction · 0.85

Calls 1

DebugFunction · 0.70

Tested by

no test coverage detected