Skip to content

Commit

Permalink
Merge pull request #738 from KeepSafe/version_in_session
Browse files Browse the repository at this point in the history
Version in session
  • Loading branch information
asvetlov committed Jan 13, 2016
2 parents e383332 + 5f010bc commit bdc201f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
22 changes: 18 additions & 4 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __init__(self, *, connector=None, loop=None, cookies=None,
headers=None, skip_auto_headers=None,
auth=None, request_class=ClientRequest,
response_class=ClientResponse,
ws_response_class=ClientWebSocketResponse):
ws_response_class=ClientWebSocketResponse,
version=aiohttp.HttpVersion11):

if connector is None:
connector = aiohttp.TCPConnector(loop=loop)
Expand All @@ -59,6 +60,7 @@ def __init__(self, *, connector=None, loop=None, cookies=None,
self._update_cookies(cookies)
self._connector = connector
self._default_auth = auth
self._version = version

# Convert to list of tuples
if headers:
Expand Down Expand Up @@ -97,12 +99,13 @@ def request(self, method, url, *,
allow_redirects=True,
max_redirects=10,
encoding='utf-8',
version=aiohttp.HttpVersion11,
version=None,
compress=None,
chunked=None,
expect100=False,
read_until_eof=True):
"""Perform HTTP request."""

return _RequestContextManager(
self._request(
method,
Expand Down Expand Up @@ -131,12 +134,18 @@ def _request(self, method, url, *,
allow_redirects=True,
max_redirects=10,
encoding='utf-8',
version=aiohttp.HttpVersion11,
version=None,
compress=None,
chunked=None,
expect100=False,
read_until_eof=True):

if version is not None:
warnings.warn("HTTP version should be specified "
"by ClientSession constructor", DeprecationWarning)
else:
version = self._version

if self.closed:
raise RuntimeError('Session is closed')

Expand Down Expand Up @@ -432,6 +441,11 @@ def cookies(self):
"""The session cookies."""
return self._cookies

@property
def version(self):
"""The session HTTP protocol version."""
return self._version

def detach(self):
"""Detach connector from session without closing the former.
Expand Down Expand Up @@ -580,7 +594,7 @@ def request(method, url, *,
allow_redirects=True,
max_redirects=10,
encoding='utf-8',
version=aiohttp.HttpVersion11,
version=None,
compress=None,
chunked=None,
expect100=False,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,17 @@ def handler(request):
(b'DATE', mock.ANY),
(b'SERVER', mock.ANY))
resp.close()


@pytest.mark.run_loop
def test_http_request_with_version(create_app_and_client, loop, warning):
@asyncio.coroutine
def handler(request):
return web.Response()

app, client = yield from create_app_and_client()
app.router.add_route('GET', '/', handler)
with warning(DeprecationWarning):
resp = yield from client.get('/', version=aiohttp.HttpVersion11)
assert resp.status == 200
resp.close()

0 comments on commit bdc201f

Please sign in to comment.