Clarify setting socket_options

There was a lot of code that would have no effect if kwargs already
had socket_options set. To make the code clearer, only execute the
code if it's going to have an effect.

Change-Id: Ic42f5a0bac07113aff59d36d19293dc6d65cd58a
This commit is contained in:
Brant Knudson
2015-08-02 11:22:18 -05:00
parent aa5738c23d
commit 22236fd763

View File

@@ -906,6 +906,7 @@ class TCPKeepAliveAdapter(requests.adapters.HTTPAdapter):
http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx
"""
def init_poolmanager(self, *args, **kwargs):
if 'socket_options' not in kwargs:
socket_options = [
# Keep Nagle's algorithm off
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
@@ -929,5 +930,6 @@ class TCPKeepAliveAdapter(requests.adapters.HTTPAdapter):
# seconds 4 times, these options should ensure that a connection
# hands for no longer than 2 minutes before a ConnectionError is
# raised.
kwargs.setdefault('socket_options', socket_options)
kwargs['socket_options'] = socket_options
super(TCPKeepAliveAdapter, self).init_poolmanager(*args, **kwargs)