Skip to content

Commit

Permalink
According to RFC 6455 websocket subprotocol preference order is
Browse files Browse the repository at this point in the history
 provided by client, not server
  • Loading branch information
asvetlov committed Jan 5, 2015
1 parent b4aaf76 commit c0e4490
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ CHANGES

- add `aiohttp.web.WebSocketResponse`

- According to RFC 6455 websocket subprotocol preference order is
provided by client, not server


0.13.1 (12-31-2014)
--------------------
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ def do_handshake(method, headers, transport, protocols=()):
# find common sub-protocol between client and server
protocol = None
if 'SEC-WEBSOCKET-PROTOCOL' in headers:
req_protocols = {str(proto.strip()) for proto in
headers['SEC-WEBSOCKET-PROTOCOL'].split(',')}
req_protocols = [str(proto.strip()) for proto in
headers['SEC-WEBSOCKET-PROTOCOL'].split(',')]

for proto in protocols:
if proto in req_protocols:
for proto in req_protocols:
if proto in protocols:
protocol = proto
break
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_handshake_protocol(self):

def test_handshake_protocol_agreement(self):
'''Tests if the right protocol is selected given multiple'''
best_proto = 'chat'
best_proto = 'worse_proto'
wanted_protos = ['best', 'chat', 'worse_proto']
server_protos = 'worse_proto,chat'

Expand Down

0 comments on commit c0e4490

Please sign in to comment.