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 httputil 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 a "keep-alive" 20 // state. It does not interrupt any connections currently in use. 21 // 22 // Borrowed from the 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 } 31