@@ -10,11 +10,13 @@ import (
10
10
"context"
11
11
"errors"
12
12
"fmt"
13
+ "net/http"
13
14
"time"
14
15
15
16
"go.mongodb.org/mongo-driver/bson"
16
17
"go.mongodb.org/mongo-driver/bson/bsoncodec"
17
18
"go.mongodb.org/mongo-driver/event"
19
+ "go.mongodb.org/mongo-driver/internal"
18
20
"go.mongodb.org/mongo-driver/internal/uuid"
19
21
"go.mongodb.org/mongo-driver/mongo/description"
20
22
"go.mongodb.org/mongo-driver/mongo/options"
@@ -64,6 +66,7 @@ type Client struct {
64
66
serverMonitor * event.ServerMonitor
65
67
sessionPool * session.Pool
66
68
timeout * time.Duration
69
+ httpClient * http.Client
67
70
68
71
// client-side encryption fields
69
72
keyVaultClientFLE * Client
@@ -173,6 +176,7 @@ func NewClient(opts ...*options.ClientOptions) (*Client, error) {
173
176
}
174
177
// Timeout
175
178
client .timeout = clientOpt .Timeout
179
+ client .httpClient = clientOpt .HTTPClient
176
180
// WriteConcern
177
181
if clientOpt .WriteConcern != nil {
178
182
client .writeConcern = clientOpt .WriteConcern
@@ -307,6 +311,11 @@ func (c *Client) Disconnect(ctx context.Context) error {
307
311
if disconnector , ok := c .deployment .(driver.Disconnector ); ok {
308
312
return replaceErrors (disconnector .Disconnect (ctx ))
309
313
}
314
+
315
+ if c .httpClient == internal .DefaultHTTPClient {
316
+ internal .CloseIdleHTTPConnections (c .httpClient )
317
+ }
318
+
310
319
return nil
311
320
}
312
321
@@ -600,6 +609,7 @@ func (c *Client) configureCryptFLE(mc *mongocrypt.MongoCrypt, opts *options.Auto
600
609
KeyFn : kr .cryptKeys ,
601
610
MarkFn : c .mongocryptdFLE .markCommand ,
602
611
TLSConfig : opts .TLSConfig ,
612
+ HTTPClient : opts .HTTPClient ,
603
613
BypassAutoEncryption : bypass ,
604
614
})
605
615
}
0 commit comments