Skip to content

Commit

Permalink
Merge branch 'release/0.3.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Nov 19, 2021
2 parents fb1ee3d + 75c5136 commit 4716258
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ jobs:
strategy:
matrix:
go-version: [1.15.x, 1.16.x, 1.17.x]
platform: [ubuntu-latest, macos-latest]
#platform: [ubuntu-latest, macos-latest, windows-latest]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
Expand All @@ -23,7 +22,7 @@ jobs:
uses: actions/checkout@v2
- name: Test package
run: |
go test -v -coverprofile=coverage.out -covermode=count ./...
go test -v -coverprofile coverage.out -covermode=count ./...
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
with:
Expand Down
10 changes: 7 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func Send(options *Options, results interface{}) (*ContentReader, error) {
return nil, errors.WithStack(err)
}

// Close indicates to close the connection or after sending this request and reading its response.
// setting this field prevents re-use of TCP connections between requests to the same hosts, as if Transport.DisableKeepAlives were set.
req.Close = true

// Setting request headers
req.Header.Set("User-Agent", options.UserAgent)
req.Header.Set("Accept", options.Accept)
Expand Down Expand Up @@ -187,7 +191,7 @@ func Send(options *Options, results interface{}) (*ContentReader, error) {
}
// Sending the request...
for attempt := 0; attempt < options.Attempts; attempt++ {
log.Tracef("Attempt #%d/%d", attempt, options.Attempts)
log.Tracef("Attempt #%d/%d", attempt+1, options.Attempts)
req.Header.Set("X-Attempt", strconv.Itoa(attempt+1))
log.Tracef("Request Headers: %#v", req.Header)
start := time.Now()
Expand All @@ -197,9 +201,9 @@ func Send(options *Options, results interface{}) (*ContentReader, error) {
if err != nil {
urlErr := &url.Error{}
if errors.As(err, &urlErr) {
if urlErr.Timeout() {
if urlErr.Timeout() || urlErr.Temporary() || urlErr.Unwrap() == io.EOF {
if attempt+1 < options.Attempts {
log.Errorf("Failed to send request after %s", duration, err)
log.Warnf("Temporary failed to send request (duration: %s/%s), Error: %s", duration, options.Timeout, err.Error()) // we don't want the stack here
log.Infof("Waiting for %s before trying again", options.InterAttemptDelay)
time.Sleep(options.InterAttemptDelay)
if req.Body != nil {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package request
var commit string

// VERSION is the version of this library
var VERSION = "0.3.8" + commit
var VERSION = "0.3.9" + commit

0 comments on commit 4716258

Please sign in to comment.