Use cleanhttp for new http clients

This commit is contained in:
Jeff Mitchell 2015-10-22 14:03:25 -04:00
parent 5a704ec14d
commit 1373a6086b
7 changed files with 18 additions and 15 deletions

View File

@ -3,9 +3,9 @@ package aws
import (
"fmt"
"log"
"net/http"
"strings"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-multierror"
"github.com/aws/aws-sdk-go/aws"
@ -101,7 +101,7 @@ func (c *Config) Client() (interface{}, error) {
Credentials: creds,
Region: aws.String(c.Region),
MaxRetries: aws.Int(c.MaxRetries),
HTTPClient: &http.Client{},
HTTPClient: cleanhttp.DefaultClient(),
}
log.Println("[INFO] Initializing IAM Connection")
@ -127,7 +127,7 @@ func (c *Config) Client() (interface{}, error) {
Credentials: creds,
Region: aws.String("us-east-1"),
MaxRetries: aws.Int(c.MaxRetries),
HTTPClient: &http.Client{},
HTTPClient: cleanhttp.DefaultClient(),
}
log.Println("[INFO] Initializing DynamoDB connection")

View File

@ -3,8 +3,8 @@ package dme
import (
"fmt"
"log"
"net/http"
"github.com/hashicorp/go-cleanhttp"
"github.com/soniah/dnsmadeeasy"
)
@ -22,7 +22,7 @@ func (c *Config) Client() (*dnsmadeeasy.Client, error) {
return nil, fmt.Errorf("Error setting up client: %s", err)
}
client.HTTP = &http.Client{}
client.HTTP = cleanhttp.DefaultClient()
if c.UseSandbox {
client.URL = dnsmadeeasy.SandboxURL

View File

@ -1,8 +1,7 @@
package packet
import (
"net/http"
"github.com/hashicorp/go-cleanhttp"
"github.com/packethost/packngo"
)
@ -16,5 +15,5 @@ type Config struct {
// Client() returns a new client for accessing packet.
func (c *Config) Client() *packngo.Client {
return packngo.NewClient(consumerToken, c.AuthToken, &http.Client{})
return packngo.NewClient(consumerToken, c.AuthToken, cleanhttp.DefaultClient())
}

View File

@ -11,6 +11,8 @@ import (
"os"
"path"
"strings"
"github.com/hashicorp/go-cleanhttp"
)
const (
@ -83,7 +85,7 @@ func (c *AtlasClient) Get() (*Payload, error) {
}
// Request the url
client := &http.Client{}
client := cleanhttp.DefaultClient()
resp, err := client.Do(req)
if err != nil {
return nil, err
@ -162,7 +164,7 @@ func (c *AtlasClient) Put(state []byte) error {
req.ContentLength = int64(len(state))
// Make the request
client := &http.Client{}
client := cleanhttp.DefaultClient()
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("Failed to upload state: %v", err)
@ -188,7 +190,7 @@ func (c *AtlasClient) Delete() error {
}
// Make the request
client := &http.Client{}
client := cleanhttp.DefaultClient()
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("Failed to delete state: %v", err)

View File

@ -5,8 +5,8 @@ import (
"fmt"
"strings"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
etcdapi "github.com/coreos/etcd/client"
"golang.org/x/net/context"
)
func etcdFactory(conf map[string]string) (Client, error) {

View File

@ -8,6 +8,8 @@ import (
"net/http/httptest"
"net/url"
"testing"
"github.com/hashicorp/go-cleanhttp"
)
func TestHTTPClient_impl(t *testing.T) {
@ -24,7 +26,7 @@ func TestHTTPClient(t *testing.T) {
t.Fatalf("err: %s", err)
}
client := &HTTPClient{URL: url, Client: &http.Client{}}
client := &HTTPClient{URL: url, Client: cleanhttp.DefaultClient()}
testClient(t, client)
}

View File

@ -5,7 +5,6 @@ import (
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
@ -14,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/go-cleanhttp"
)
func s3Factory(conf map[string]string) (Client, error) {
@ -76,7 +76,7 @@ func s3Factory(conf map[string]string) (Client, error) {
awsConfig := &aws.Config{
Credentials: credentialsProvider,
Region: aws.String(regionName),
HTTPClient: &http.Client{},
HTTPClient: cleanhttp.DefaultClient(),
}
nativeClient := s3.New(awsConfig)