Fix up path encoding for WS too

This commit is contained in:
Andrew Godwin 2016-04-26 13:37:50 +01:00
parent 1fcb76e956
commit e9d61fc1c8
2 changed files with 18 additions and 6 deletions

View File

@ -4,9 +4,9 @@ import logging
import six
import time
from twisted.web import http
from twisted.protocols.policies import ProtocolWrapper
from six.moves.urllib_parse import unquote_plus
from twisted.protocols.policies import ProtocolWrapper
from twisted.web import http
from .ws_protocol import WebSocketProtocol, WebSocketFactory
@ -118,7 +118,8 @@ class WebRequest(http.Request):
"server": [self.host.host, self.host.port],
})
def unquote(self, value):
@classmethod
def unquote(cls, value):
"""
Python 2 and 3 compat layer for utf-8 unquoting
"""

View File

@ -1,9 +1,10 @@
from __future__ import unicode_literals
import logging
import six
import time
import traceback
from six.moves.urllib.parse import urlencode
from six.moves.urllib_parse import unquote_plus, urlencode
from autobahn.twisted.websocket import WebSocketServerProtocol, WebSocketServerFactory
@ -43,9 +44,9 @@ class WebSocketProtocol(WebSocketServerProtocol):
# Make initial request info dict from request (we only have it here)
self.path = request.path.encode("ascii")
self.request_info = {
"path": self.path,
"path": self.unquote(self.path),
"headers": clean_headers,
"query_string": query_string,
"query_string": self.unquote(query_string),
"client": [self.transport.getPeer().host, self.transport.getPeer().port],
"server": [self.transport.getHost().host, self.transport.getHost().port],
"reply_channel": self.reply_channel,
@ -61,6 +62,16 @@ class WebSocketProtocol(WebSocketServerProtocol):
if ws_protocol and ws_protocol in self.factory.protocols:
return ws_protocol
@classmethod
def unquote(cls, value):
"""
Python 2 and 3 compat layer for utf-8 unquoting
"""
if six.PY2:
return unquote_plus(value).decode("utf8")
else:
return unquote_plus(value.decode("ascii"))
def onOpen(self):
# Send news that this channel is open
logger.debug("WebSocket open for %s", self.reply_channel)