Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-3373

Use non-default global DefaultTransport for DefaultClient

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.0.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Go Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Detailed steps to reproduce the problem?

      This occurs when the user changes the global http.DefaultTransport variable:

      package main
      
      import (
      	"context"
      	"net/http"
      
      	_ "github.com/motemen/go-loghttp/global" // Just this line!
      	"go.mongodb.org/mongo-driver/v2/mongo"
      )
      
      type nonDefaultTransport struct{}
      
      var _ http.RoundTripper = &nonDefaultTransport{}
      
      func (*nonDefaultTransport) RoundTrip(*http.Request) (*http.Response, error) { return nil, nil }
      
      func main() {
      	http.DefaultTransport = &nonDefaultTransport{}
      
      	client, err := mongo.Connect(context.Background())
      	if err != nil {
      		panic(err)
      	}
      
      	defer func() { _ = client.Disconnect(context.Background()) }()
      }
      

      Definition of done: what must be done to consider the task complete?

      We should not define a global client, create one as needed.

      The exact Go version used, with patch level:

      go version go1.23.1 darwin/arm64

      The exact version of the Go driver used:

      1.17.1

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      NA

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      Sonoma 14.5

      Security Vulnerabilities

      NA

            Assignee:
            Unassigned Unassigned
            Reporter:
            preston.vasquez@mongodb.com Preston Vasquez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: