Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions cert_error_go120.go → cert_error.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 0 additions & 14 deletions cert_error_go119.go

This file was deleted.

17 changes: 13 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down