diff --git a/cert_error_go120.go b/cert_error.go similarity index 85% rename from cert_error_go120.go rename to cert_error.go index a3cd315..a775f70 100644 --- a/cert_error_go120.go +++ b/cert_error.go @@ -1,9 +1,6 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:build go1.20 -// +build go1.20 - package retryablehttp import "crypto/tls" diff --git a/cert_error_go119.go b/cert_error_go119.go deleted file mode 100644 index b2b27e8..0000000 --- a/cert_error_go119.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -//go:build !go1.20 -// +build !go1.20 - -package retryablehttp - -import "crypto/x509" - -func isCertError(err error) bool { - _, ok := err.(x509.UnknownAuthorityError) - return ok -} diff --git a/client.go b/client.go index 91059f7..7878b4b 100644 --- a/client.go +++ b/client.go @@ -266,7 +266,7 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro case io.ReadSeeker: raw := body bodyReader = func() (io.Reader, error) { - _, err := raw.Seek(0, 0) + _, err := raw.Seek(0, io.SeekStart) return io.NopCloser(raw), err } if lr, ok := raw.(LenReader); ok { @@ -865,7 +865,7 @@ func Get(url string) (*http.Response, error) { // Get is a convenience helper for doing simple GET requests. func (c *Client) Get(url string) (*http.Response, error) { - req, err := NewRequest("GET", url, nil) + req, err := NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err } @@ -879,7 +879,7 @@ func Head(url string) (*http.Response, error) { // Head is a convenience method for doing simple HEAD requests. func (c *Client) Head(url string) (*http.Response, error) { - req, err := NewRequest("HEAD", url, nil) + req, err := NewRequest(http.MethodHead, url, nil) if err != nil { return nil, err } @@ -895,7 +895,7 @@ func Post(url, bodyType string, body interface{}) (*http.Response, error) { // Post is a convenience method for doing simple POST requests. // The bodyType parameter sets the "Content-Type" header of the request. func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error) { - req, err := NewRequest("POST", url, body) + req, err := NewRequest(http.MethodPost, url, body) if err != nil { return nil, err } @@ -915,6 +915,15 @@ func (c *Client) PostForm(url string, data url.Values) (*http.Response, error) { return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) } +// CloseIdleConnections closes any connections on its Transport which were previously +// connected from previous requests but are now sitting idle in a "keep-alive" state. +// It does not interrupt any connections currently in use. +// +// This implementation delegate the call to inner HTTPClient. +func (c *Client) CloseIdleConnections() { + c.HTTPClient.CloseIdleConnections() +} + // StandardClient returns a stdlib *http.Client with a custom Transport, which // shims in a *retryablehttp.Client for added retries. func (c *Client) StandardClient() *http.Client { diff --git a/roundtripper.go b/roundtripper.go index 8c407ad..1901406 100644 --- a/roundtripper.go +++ b/roundtripper.go @@ -10,6 +10,9 @@ import ( "sync" ) +// ensure RoundTripper implements http.RoundTripper interface. +var _ http.RoundTripper = (*RoundTripper)(nil) + // RoundTripper implements the http.RoundTripper interface, using a retrying // HTTP client to execute requests. //