From 9392e526eab6baf37f81aa7cb3a2c5d2326fe733 Mon Sep 17 00:00:00 2001 From: Flavio Curella Date: Wed, 29 Jun 2016 11:14:02 -0500 Subject: [PATCH] parse multiple subprotocols and return the first match --- daphne/ws_protocol.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index 0bf3c45..bb67d8f 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -68,8 +68,13 @@ class WebSocketProtocol(WebSocketServerProtocol): ws_protocol = None for header, value in self.clean_headers: - if header == 'sec-websocket-protocol': - ws_protocol = value + if header == b'sec-websocket-protocol': + protocols = [x.strip() for x in self.unquote(value).split(",")] + for protocol in protocols: + if protocol in self.factory.protocols: + ws_protocol = protocol + break + if ws_protocol and ws_protocol in self.factory.protocols: return ws_protocol