Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/net/http nil transport should default to http.DefaultTransport #1572

Merged
merged 4 commits into from
Nov 11, 2022

Conversation

dillonstreator
Copy link
Contributor

What does this PR do?

Fixes #1223
If a nil transport is provided to WrapRoundTripper, default to http.DefaultTransport

Motivation

The following program panics at runtime:

package main

import (
	"net/http"

	httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
)

func main() {

	httpClient := &http.Client{}

	httpClient.Transport = httptrace.WrapRoundTripper(httpClient.Transport)

	_, _ = httpClient.Get("https://www.google.com")

}

The panic comes when httpClient.Get is called even though nil shouldn't be a valid parameter for WrapRoundTripper. In some programs, that panic might not come as quickly as seen above.

This is interesting because go itself does not require a transport to be specific on the http.Client as it falls back to the http.DefaultTransport. As such, it's not uncommon for an http client to be created without explicitly specifying the transport.

Describe how to test/QA your changes

N/A

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • Changed code has unit tests for its functionality.
  • If this interacts with the agent in a new way, a system test has been added.

@dillonstreator dillonstreator requested a review from a team November 9, 2022 01:12
dillonstreator and others added 2 commits November 10, 2022 08:46
Co-authored-by: Andrew Glaude <ajgajg1134@gmail.com>
@ajgajg1134 ajgajg1134 merged commit 2f2d7dc into DataDog:main Nov 11, 2022
@dillonstreator dillonstreator deleted the fix-1223 branch November 11, 2022 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nil transport should default to http.DefaultTransport
2 participants