Skip to content

Commit

Permalink
contrib/net/http nil transport should default to http.DefaultTransport (
Browse files Browse the repository at this point in the history
#1572)

* null transport should default to http.DefaultTransport

* Test name casing update

Co-authored-by: Andrew Glaude <ajgajg1134@gmail.com>

Co-authored-by: Andrew Glaude <ajgajg1134@gmail.com>
  • Loading branch information
dillonstreator and ajgajg1134 authored Nov 11, 2022
1 parent 364ae14 commit 2f2d7dc
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 TestWrapRoundTripperAllowNilTransport(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 2f2d7dc

Please sign in to comment.