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

Add initial support for PerMessage Deflate #2273

Merged
merged 34 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
00bae99
Add initial support for PerMessage Deflate
fanthos Sep 16, 2017
405be9a
Add Client websocket deflate init support.(not tested)
fanthos Sep 16, 2017
5017f01
Update parser to support compress parse
fanthos Sep 17, 2017
70ab0e9
fix for CI
fanthos Sep 17, 2017
e0a459c
add document for compress
fanthos Sep 17, 2017
52de28c
Improve compress detect logic
fanthos Sep 17, 2017
048a8f2
Complete Client websocket deflate support
fanthos Sep 17, 2017
72127c5
Merge branch 'master' into master
fanthos Sep 17, 2017
4c55414
update
fanthos Sep 17, 2017
3c6029e
sort import
fanthos Sep 17, 2017
79714a7
Add more tests
fanthos Sep 17, 2017
e51f48d
fix typo
fanthos Sep 17, 2017
f8f0f21
add 2 more tests
fanthos Sep 17, 2017
63bd563
Using regex to parse header
fanthos Sep 18, 2017
895ea75
remove dead code
fanthos Sep 18, 2017
adf31e0
coverage
fanthos Sep 18, 2017
39a15ef
Merge branch 'master' into master
asvetlov Sep 18, 2017
b45c0ba
Add reader deflate flag support.
fanthos Sep 19, 2017
a04c1c9
Merge branch 'master' of https://github.com/fanthos/aiohttp
fanthos Sep 19, 2017
c3c640e
Merge branch 'master' into master
asvetlov Sep 19, 2017
99b50d5
fixed
fanthos Sep 19, 2017
268da36
Merge branch 'master' of https://github.com/fanthos/aiohttp
fanthos Sep 19, 2017
2e961b3
Merge branch 'master' into master
asvetlov Sep 20, 2017
b91d1c7
Using array.join instead of strcat.
fanthos Sep 21, 2017
c95a7f4
Merge branch 'master' of https://github.com/fanthos/aiohttp
fanthos Sep 21, 2017
c911749
fix
fanthos Sep 22, 2017
01ea9b1
Update http_websocket.py
asvetlov Sep 22, 2017
97a2c1e
Merge branch 'master' into master
asvetlov Sep 23, 2017
c98c777
Update 2273.feature
asvetlov Sep 23, 2017
fff88de
add docs for server
fanthos Sep 23, 2017
26e7bac
Merge branch 'master' into master
asvetlov Sep 23, 2017
e5c651d
Merge branch 'master' into master
asvetlov Sep 25, 2017
8da8460
Update client.py
asvetlov Sep 26, 2017
22fb3f9
Update client_reference.rst
asvetlov Sep 26, 2017
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
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Arthur Darcet
Ben Bader
Benedikt Reinartz
Boris Feld
Boyi Chen
Brett Cannon
Brian C. Lane
Brian Muller
Expand Down
39 changes: 34 additions & 5 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .helpers import (PY_35, CeilTimeout, ProxyInfo, TimeoutHandle,
_BaseCoroMixin, deprecated_noop, sentinel)
from .http import WS_KEY, WebSocketReader, WebSocketWriter
from .http_websocket import WSHandshakeError, ws_ext_gen, ws_ext_parse
from .streams import FlowControlDataQueue


Expand Down Expand Up @@ -370,7 +371,8 @@ def ws_connect(self, url, *,
origin=None,
headers=None,
proxy=None,
proxy_auth=None):
proxy_auth=None,
compress=0):
"""Initiate websocket connection."""
return _WSRequestContextManager(
self._ws_connect(url,
Expand All @@ -384,7 +386,8 @@ def ws_connect(self, url, *,
origin=origin,
headers=headers,
proxy=proxy,
proxy_auth=proxy_auth))
proxy_auth=proxy_auth,
compress=compress))

@asyncio.coroutine
def _ws_connect(self, url, *,
Expand All @@ -398,7 +401,8 @@ def _ws_connect(self, url, *,
origin=None,
headers=None,
proxy=None,
proxy_auth=None):
proxy_auth=None,
compress=0):
Copy link
Member

Choose a reason for hiding this comment

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

Let's use compress=15 as initial value and don't accept True


if headers is None:
headers = CIMultiDict()
Expand All @@ -420,6 +424,9 @@ def _ws_connect(self, url, *,
headers[hdrs.SEC_WEBSOCKET_PROTOCOL] = ','.join(protocols)
if origin is not None:
headers[hdrs.ORIGIN] = origin
if compress:
extstr = ws_ext_gen(compress=compress)
headers[hdrs.SEC_WEBSOCKET_EXTENSIONS] = extstr

# send request
resp = yield from self.get(url, headers=headers,
Expand Down Expand Up @@ -478,12 +485,32 @@ def _ws_connect(self, url, *,
protocol = proto
break

# websocket compress
notakeover = False
if compress:
compress_hdrs = resp.headers.get(hdrs.SEC_WEBSOCKET_EXTENSIONS)
if compress_hdrs:
try:
compress, notakeover = ws_ext_parse(compress_hdrs)
except WSHandshakeError as exc:
raise WSServerHandshakeError(
resp.request_info,
resp.history,
message=exc.args[0],
code=resp.status,
headers=resp.headers)
else:
compress = 0
notakeover = False

proto = resp.connection.protocol
reader = FlowControlDataQueue(
proto, limit=2 ** 16, loop=self._loop)
proto.set_parser(WebSocketReader(reader), reader)
resp.connection.writer.set_tcp_nodelay(True)
writer = WebSocketWriter(resp.connection.writer, use_mask=True)
writer = WebSocketWriter(
resp.connection.writer, use_mask=True,
compress=compress, notakeover=notakeover)
except Exception:
resp.close()
raise
Expand All @@ -497,7 +524,9 @@ def _ws_connect(self, url, *,
autoping,
self._loop,
receive_timeout=receive_timeout,
heartbeat=heartbeat)
heartbeat=heartbeat,
compress=compress,
client_notakeover=notakeover)

def _prepare_headers(self, headers):
""" Add default headers and transform it to CIMultiDict
Expand Down
13 changes: 12 additions & 1 deletion aiohttp/client_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ClientWebSocketResponse:

def __init__(self, reader, writer, protocol,
response, timeout, autoclose, autoping, loop, *,
receive_timeout=None, heartbeat=None):
receive_timeout=None, heartbeat=None,
compress=0, client_notakeover=False):
self._response = response
self._conn = response.connection

Expand All @@ -35,6 +36,8 @@ def __init__(self, reader, writer, protocol,
self._loop = loop
self._waiting = None
self._exception = None
self._compress = compress
self._client_notakeover = client_notakeover

self._reset_heartbeat()

Expand Down Expand Up @@ -82,6 +85,14 @@ def close_code(self):
def protocol(self):
return self._protocol

@property
def compress(self):
return self._compress

@property
def client_notakeover(self):
return self._client_notakeover

def get_extra_info(self, name, default=None):
"""extra info from connection transport"""
try:
Expand Down
1 change: 1 addition & 0 deletions aiohttp/hdrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
SEC_WEBSOCKET_ACCEPT = istr('SEC-WEBSOCKET-ACCEPT')
SEC_WEBSOCKET_VERSION = istr('SEC-WEBSOCKET-VERSION')
SEC_WEBSOCKET_PROTOCOL = istr('SEC-WEBSOCKET-PROTOCOL')
SEC_WEBSOCKET_EXTENSIONS = istr('SEC-WEBSOCKET-EXTENSIONS')
SEC_WEBSOCKET_KEY = istr('SEC-WEBSOCKET-KEY')
SEC_WEBSOCKET_KEY1 = istr('SEC-WEBSOCKET-KEY1')
SERVER = istr('SERVER')
Expand Down
Loading