Skip to content

Commit

Permalink
Merge pull request #319 from hashicorp/cleanhttp
Browse files Browse the repository at this point in the history
Use cleanhttp for truly clean clients and transports.
  • Loading branch information
dadgar committed Oct 22, 2015
2 parents adbdc0d + b0aac09 commit ffaacc3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"os"
"strconv"
"time"

"github.com/hashicorp/cleanhttp"
)

// QueryOptions are used to parameterize a query
Expand Down Expand Up @@ -86,7 +88,7 @@ type Config struct {
func DefaultConfig() *Config {
config := &Config{
Address: "http://127.0.0.1:4646",
HttpClient: &http.Client{},
HttpClient: cleanhttp.DefaultClient(),
}
if addr := os.Getenv("NOMAD_ADDR"); addr != "" {
config.Address = addr
Expand Down
10 changes: 7 additions & 3 deletions client/fingerprint/env_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/hashicorp/cleanhttp"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/nomad/structs"
)
Expand Down Expand Up @@ -93,7 +94,8 @@ func (f *EnvAWSFingerprint) Fingerprint(cfg *config.Config, node *structs.Node)

// assume 2 seconds is enough time for inside AWS network
client := &http.Client{
Timeout: 2 * time.Second,
Timeout: 2 * time.Second,
Transport: cleanhttp.DefaultTransport(),
}

keys := []string{
Expand Down Expand Up @@ -164,7 +166,8 @@ func isAWS() bool {

// assume 2 seconds is enough time for inside AWS network
client := &http.Client{
Timeout: 2 * time.Second,
Timeout: 2 * time.Second,
Transport: cleanhttp.DefaultTransport(),
}

// Query the metadata url for the ami-id, to veryify we're on AWS
Expand Down Expand Up @@ -207,7 +210,8 @@ func (f *EnvAWSFingerprint) linkSpeed() int {

// assume 2 seconds is enough time for inside AWS network
client := &http.Client{
Timeout: 2 * time.Second,
Timeout: 2 * time.Second,
Transport: cleanhttp.DefaultTransport(),
}

res, err := client.Get(metadataURL + "instance-type")
Expand Down
4 changes: 3 additions & 1 deletion client/fingerprint/env_gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

"github.com/hashicorp/cleanhttp"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/nomad/structs"
)
Expand Down Expand Up @@ -61,7 +62,8 @@ func NewEnvGCEFingerprint(logger *log.Logger) Fingerprint {

// assume 2 seconds is enough time for inside GCE network
client := &http.Client{
Timeout: 2 * time.Second,
Timeout: 2 * time.Second,
Transport: cleanhttp.DefaultTransport(),
}

return &EnvGCEFingerprint{
Expand Down
4 changes: 3 additions & 1 deletion testutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"os/exec"
"sync/atomic"
"testing"

"github.com/hashicorp/cleanhttp"
)

// offset is used to atomically increment the port numbers.
Expand Down Expand Up @@ -156,7 +158,7 @@ func NewTestServer(t *testing.T, cb ServerConfigCallback) *TestServer {
t.Fatalf("err: %s", err)
}

client := &http.Client{}
client := cleanhttp.DefaultClient()

server := &TestServer{
Config: nomadConfig,
Expand Down

0 comments on commit ffaacc3

Please sign in to comment.