diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc13f74..639d2cc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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: diff --git a/request.go b/request.go index 9596480..c7ce765 100644 --- a/request.go +++ b/request.go @@ -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) @@ -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() @@ -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 { diff --git a/version.go b/version.go index a302221..772f2f4 100644 --- a/version.go +++ b/version.go @@ -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