mirror of
https://github.com/django/daphne.git
synced 2024-11-22 07:56:34 +03:00
Fix up path encoding for WS too
This commit is contained in:
parent
1fcb76e956
commit
e9d61fc1c8
|
@ -4,9 +4,9 @@ import logging
|
||||||
import six
|
import six
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from twisted.web import http
|
|
||||||
from twisted.protocols.policies import ProtocolWrapper
|
|
||||||
from six.moves.urllib_parse import unquote_plus
|
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
|
from .ws_protocol import WebSocketProtocol, WebSocketFactory
|
||||||
|
|
||||||
|
@ -118,7 +118,8 @@ class WebRequest(http.Request):
|
||||||
"server": [self.host.host, self.host.port],
|
"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
|
Python 2 and 3 compat layer for utf-8 unquoting
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import six
|
||||||
import time
|
import time
|
||||||
import traceback
|
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
|
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)
|
# Make initial request info dict from request (we only have it here)
|
||||||
self.path = request.path.encode("ascii")
|
self.path = request.path.encode("ascii")
|
||||||
self.request_info = {
|
self.request_info = {
|
||||||
"path": self.path,
|
"path": self.unquote(self.path),
|
||||||
"headers": clean_headers,
|
"headers": clean_headers,
|
||||||
"query_string": query_string,
|
"query_string": self.unquote(query_string),
|
||||||
"client": [self.transport.getPeer().host, self.transport.getPeer().port],
|
"client": [self.transport.getPeer().host, self.transport.getPeer().port],
|
||||||
"server": [self.transport.getHost().host, self.transport.getHost().port],
|
"server": [self.transport.getHost().host, self.transport.getHost().port],
|
||||||
"reply_channel": self.reply_channel,
|
"reply_channel": self.reply_channel,
|
||||||
|
@ -61,6 +62,16 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
if ws_protocol and ws_protocol in self.factory.protocols:
|
if ws_protocol and ws_protocol in self.factory.protocols:
|
||||||
return ws_protocol
|
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):
|
def onOpen(self):
|
||||||
# Send news that this channel is open
|
# Send news that this channel is open
|
||||||
logger.debug("WebSocket open for %s", self.reply_channel)
|
logger.debug("WebSocket open for %s", self.reply_channel)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user