Skip to content

Commit

Permalink
Pass separate client objects for awsSigner and default http
Browse files Browse the repository at this point in the history
  • Loading branch information
RMPall committed Feb 16, 2022
1 parent 586d8d0 commit c41e334
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
38 changes: 19 additions & 19 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package http
//go:generate moq -out mock_client.go . Clienter

import (
"fmt"
"io"
"math"
"math/rand"
Expand Down Expand Up @@ -38,18 +37,6 @@ var DefaultTransport = &http.Transport{
IdleConnTimeout: 30 * time.Second,
}

// DefaultClient is a dp-net specific http client with sensible timeouts,
// exponential backoff, and a contextual dialer.
var DefaultClient = &Client{
MaxRetries: 3,
RetryTime: 20 * time.Millisecond,

HTTPClient: &http.Client{
Timeout: 10 * time.Second,
Transport: DefaultTransport,
},
}

// Clienter provides an interface for methods on an HTTP Client.
type Clienter interface {
SetTimeout(timeout time.Duration)
Expand All @@ -70,19 +57,33 @@ type Clienter interface {

// NewClient returns a copy of DefaultClient.
func NewClient() Clienter {
newClient := *DefaultClient
return &newClient
return &Client{
MaxRetries: 3,
RetryTime: 20 * time.Millisecond,

HTTPClient: &http.Client{
Timeout: 10 * time.Second,
Transport: DefaultTransport,
},
}
}

func NewClientWithAwsSigner(awsFilename, awsProfile, awsRegion, awsService string) (Clienter, error) {
fmt.Println("bug check - inside the AWS signer")
newClient := *DefaultClient
newClient := &Client{
MaxRetries: 3,
RetryTime: 20 * time.Millisecond,

HTTPClient: &http.Client{
Timeout: 10 * time.Second,
Transport: DefaultTransport,
},
}
awsRoundTripper, err := NewAWSSignerRoundTripper(awsFilename, awsProfile, awsRegion, awsService, DefaultTransport)
if err != nil {
return nil, err
}
newClient.HTTPClient.Transport = awsRoundTripper
return &newClient, nil
return newClient, nil
}

// ClientWithTimeout facilitates creating a client and setting request timeout.
Expand All @@ -96,7 +97,6 @@ func ClientWithTimeout(c Clienter, timeout time.Duration) Clienter {

// Clienter roundtripper calls the httpclient roundtripper.
func (c *Client) RoundTrip(req *http.Request) (*http.Response, error) {
fmt.Printf("bug check - inside RoundTrip: %s", req.Header.Get("Authorization"))
return c.HTTPClient.Transport.RoundTrip(req)
}

Expand Down
2 changes: 0 additions & 2 deletions http/custom_roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func NewAWSSignerRoundTripper(awsFilename, awsProfile, awsRegion, awsService str
}

func (srt *AwsSignerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
fmt.Printf("bug check - inside the AWS signer round tripper: %s", req.Header.Get("Authorization"))

var body []byte
var err error
if req.Body != nil {
Expand Down

0 comments on commit c41e334

Please sign in to comment.