File tree 2 files changed +28
-3
lines changed
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -462,10 +462,19 @@ def _get_pool_options(self, ca_certs):
462
462
"ca_certs" : ca_certs or certifi .where (),
463
463
}
464
464
465
+ socket_options = []
466
+
465
467
if self .options ["socket_options" ]:
466
- options ["socket_options" ] = self .options ["socket_options" ]
467
- elif self .options ["keep_alive" ]:
468
- options ["socket_options" ] = KEEP_ALIVE_SOCKET_OPTIONS
468
+ socket_options = self .options ["socket_options" ]
469
+
470
+ if self .options ["keep_alive" ]:
471
+ used_options = {(o [0 ], o [1 ]) for o in socket_options }
472
+ for default_option in KEEP_ALIVE_SOCKET_OPTIONS :
473
+ if (default_option [0 ], default_option [1 ]) not in used_options :
474
+ socket_options .append (default_option )
475
+
476
+ if socket_options :
477
+ options ["socket_options" ] = socket_options
469
478
470
479
return options
471
480
Original file line number Diff line number Diff line change @@ -187,6 +187,22 @@ def test_socket_options_override_keep_alive(make_client):
187
187
assert options ["socket_options" ] == socket_options
188
188
189
189
190
+ def test_socket_options_merge_keep_alive_with_socket_options (make_client ):
191
+ socket_options = [
192
+ (socket .SOL_SOCKET , socket .SO_KEEPALIVE , 42 ),
193
+ (socket .SOL_TCP , socket .TCP_KEEPINTVL , 42 ),
194
+ ]
195
+
196
+ client = make_client (socket_options = socket_options , keep_alive = True )
197
+
198
+ options = client .transport ._get_pool_options ([])
199
+ assert options ["socket_options" ] == [
200
+ (socket .SOL_SOCKET , socket .SO_KEEPALIVE , 42 ),
201
+ (socket .SOL_TCP , socket .TCP_KEEPINTVL , 42 ),
202
+ (socket .SOL_TCP , socket .TCP_KEEPCNT , 6 ),
203
+ ]
204
+
205
+
190
206
def test_keep_alive_off_by_default (make_client ):
191
207
client = make_client ()
192
208
You can’t perform that action at this time.
0 commit comments