do - execute http request.
(req *http.Request)
| 615 | |
| 616 | // do - execute http request. |
| 617 | func (c *Client) do(req *http.Request) (resp *http.Response, err error) { |
| 618 | defer func() { |
| 619 | if IsNetworkOrHostDown(err, false) { |
| 620 | c.markOffline() |
| 621 | } |
| 622 | }() |
| 623 | |
| 624 | resp, err = c.httpClient.Do(req) |
| 625 | if err != nil { |
| 626 | // Handle this specifically for now until future Golang versions fix this issue properly. |
| 627 | if urlErr, ok := err.(*url.Error); ok { |
| 628 | if strings.Contains(urlErr.Err.Error(), "EOF") { |
| 629 | return nil, &url.Error{ |
| 630 | Op: urlErr.Op, |
| 631 | URL: urlErr.URL, |
| 632 | Err: errors.New("Connection closed by foreign host " + urlErr.URL + ". Retry again."), |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | return nil, err |
| 637 | } |
| 638 | |
| 639 | // Response cannot be non-nil, report error if thats the case. |
| 640 | if resp == nil { |
| 641 | msg := "Response is empty. " + reportIssue |
| 642 | return nil, errInvalidArgument(msg) |
| 643 | } |
| 644 | |
| 645 | // If trace is enabled, dump http request and response, |
| 646 | // except when the traceErrorsOnly enabled and the response's status code is ok |
| 647 | if c.isTraceEnabled && (!c.traceErrorsOnly || resp.StatusCode != http.StatusOK) { |
| 648 | err = c.dumpHTTP(req, resp) |
| 649 | if err != nil { |
| 650 | return nil, err |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | return resp, nil |
| 655 | } |
| 656 | |
| 657 | // List of success status. |
| 658 | var successStatus = set.CreateIntSet( |
no test coverage detected