Skip to content

Commit

Permalink
null transport should default to http.DefaultTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonstreator committed Nov 9, 2022
1 parent 61c5926 commit 9060d57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contrib/net/http/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (rt *roundTripper) Unwrap() http.RoundTripper {
// WrapRoundTripper returns a new RoundTripper which traces all requests sent
// over the transport.
func WrapRoundTripper(rt http.RoundTripper, opts ...RoundTripperOption) http.RoundTripper {
if rt == nil {
rt = http.DefaultTransport
}
cfg := newRoundTripperConfig()
for _, opt := range opts {
opt(cfg)
Expand Down
12 changes: 12 additions & 0 deletions contrib/net/http/roundtripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
)

func TestWrapRoundTripper_allow_nil_transport(t *testing.T) {
assert := assert.New(t)

httpClient := &http.Client{}
httpClient.Transport = WrapRoundTripper(httpClient.Transport)

wrapped, ok := httpClient.Transport.(*roundTripper)
assert.True(ok)

assert.Equal(http.DefaultTransport, wrapped.base)
}

func TestRoundTripper(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
Expand Down

0 comments on commit 9060d57

Please sign in to comment.