github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/internal/http.go (about)

     1  // Copyright (C) MongoDB, Inc. 2022-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package internal // import "go.mongodb.org/mongo-driver/internal"
     8  
     9  import (
    10  	"net/http"
    11  )
    12  
    13  // DefaultHTTPClient is the default HTTP client used across the driver.
    14  var DefaultHTTPClient = &http.Client{
    15  	Transport: http.DefaultTransport.(*http.Transport).Clone(),
    16  }
    17  
    18  // CloseIdleHTTPConnections closes any connections which were previously
    19  // connected from previous requests but are now sitting idle in
    20  // a "keep-alive" state. It does not interrupt any connections currently
    21  // in use.
    22  // Borrowed from go standard library.
    23  func CloseIdleHTTPConnections(client *http.Client) {
    24  	type closeIdler interface {
    25  		CloseIdleConnections()
    26  	}
    27  	if tr, ok := client.Transport.(closeIdler); ok {
    28  		tr.CloseIdleConnections()
    29  	}
    30  }