Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local socket binding for TCPConnector #678

Merged
merged 6 commits into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,14 @@ class TCPConnector(BaseConnector):
https://en.wikipedia.org/wiki/Transport_Layer_Security#Certificate_pinning
:param bool resolve: Set to True to do DNS lookup for host name.
:param family: socket address family
:param local_addr: local :class:`tuple` of (host, port) to bind socket to
:param args: see :class:`BaseConnector`
:param kwargs: see :class:`BaseConnector`
"""

def __init__(self, *, verify_ssl=True, fingerprint=None,
resolve=_marker, use_dns_cache=_marker,
family=0, ssl_context=None,
family=0, ssl_context=None, local_addr=None,
**kwargs):
super().__init__(**kwargs)

Expand Down Expand Up @@ -447,6 +448,7 @@ def __init__(self, *, verify_ssl=True, fingerprint=None,
self._cached_hosts = {}
self._ssl_context = ssl_context
self._family = family
self._local_addr = local_addr

@property
def verify_ssl(self):
Expand Down Expand Up @@ -572,7 +574,8 @@ def _create_connection(self, req):
self._factory, host, port,
ssl=sslcontext, family=hinfo['family'],
proto=hinfo['proto'], flags=hinfo['flags'],
server_hostname=hinfo['hostname'] if sslcontext else None)
server_hostname=hinfo['hostname'] if sslcontext else None,
local_addr=self._local_addr)
has_cert = transp.get_extra_info('sslcontext')
if has_cert and self._fingerprint:
sock = transp.get_extra_info('socket')
Expand Down
5 changes: 4 additions & 1 deletion docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ TCPConnector
family=0, \
ssl_context=None, conn_timeout=None, \
keepalive_timeout=30, limit=None, share_cookies=False, \
force_close=False, loop=None)
force_close=False, loop=None, local_addr=None)

Connector for working with *HTTP* and *HTTPS* via *TCP* sockets.

Expand Down Expand Up @@ -697,6 +697,9 @@ TCPConnector
*ssl_context* may be used for configuring certification
authority channel, supported SSL options etc.

:param tuple local_addr: tuple of ``(local_addr, local_port)`` used to bind
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use markup here but update ./docs/client_reference.rst also.
(local_addr, local_port) should be (local_host, local_port) pair.

socket locally.

.. attribute:: verify_ssl

Check *ssl certifications* if ``True``.
Expand Down