Commit b0b7ab71 authored by Keita Suzuki's avatar Keita Suzuki Committed by Commit Bot

Update blink web_test for websockets to python 3 compatible

Current websocket handlers used in blink web_test only works with python
2. Update them to python 3 compatible versions to keep them working.

Change-Id: I7d8d4f5b858536de25135a05f5ac84643108318c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2041378
Commit-Queue: Keita Suzuki <suzukikeita@google.com>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747115}
parent af5569c4
...@@ -3,15 +3,15 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,15 +3,15 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
msg = 'HTTP/1.1 101 Switching Protocols\r\n' msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
msg += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'\xa5:\r\n'
msg += '\xa5:\r\n' b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
msg += '\r\n'
request.connection.write(msg) request.connection.write(msg)
print msg
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -8,7 +8,7 @@ def web_socket_do_extra_handshake(request): ...@@ -8,7 +8,7 @@ def web_socket_do_extra_handshake(request):
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
# '\xff' will never appear in UTF-8 encoded data. # '\xff' will never appear in UTF-8 encoded data.
payload = 'This text should be ignored. \xff' payload = b'This text should be ignored. \xff'
request.connection.write( request.connection.write(
stream.create_header(common.OPCODE_TEXT, len(payload), 1, 0, 0, 0, 0) + stream.create_header(common.OPCODE_TEXT, len(payload), 1, 0, 0, 0, 0) +
payload) payload)
...@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE ...@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Connected Connected
Closed Closed
PASS receivedMessage is undefined. PASS receivedMessage is undefined.
PASS closeEvent.reason is "close_frame[:2]='\\x88\\x80'" PASS closeEvent.reason is "close_frame[:2]='88 80'"
PASS closeEvent.wasClean is true PASS closeEvent.wasClean is true
PASS successfullyParsed is true PASS successfullyParsed is true
......
...@@ -32,7 +32,7 @@ ws.onclose = function(event) ...@@ -32,7 +32,7 @@ ws.onclose = function(event)
debug("Closed"); debug("Closed");
closeEvent = event; closeEvent = event;
shouldBeUndefined("receivedMessage"); shouldBeUndefined("receivedMessage");
shouldBeEqualToString("closeEvent.reason", "close_frame[:2]='\\x88\\x80'"); shouldBeEqualToString("closeEvent.reason", "close_frame[:2]='88 80'");
shouldBeTrue("closeEvent.wasClean"); shouldBeTrue("closeEvent.wasClean");
finishJSTest(); finishJSTest();
}; };
......
...@@ -2,6 +2,7 @@ import struct ...@@ -2,6 +2,7 @@ import struct
from mod_pywebsocket import msgutil from mod_pywebsocket import msgutil
from mod_pywebsocket import stream from mod_pywebsocket import stream
from mod_pywebsocket import util
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
...@@ -16,7 +17,10 @@ def web_socket_transfer_data(request): ...@@ -16,7 +17,10 @@ def web_socket_transfer_data(request):
# Send only first two bytes of the received frame. The remaining four bytes # Send only first two bytes of the received frame. The remaining four bytes
# are "masking key", which changes every time the test runs. # are "masking key", which changes every time the test runs.
data = struct.pack('!H', 1000) + 'close_frame[:2]=%r' % close_frame[:2]
message = "close_frame[:2]='%s'" % util.hexify(close_frame[:2])
data = struct.pack('!H', 1000) + message.encode('UTF-8')
request.connection.write(stream.create_close_frame(data)) request.connection.write(stream.create_close_frame(data))
# Tell pywebsocket we have sent a close frame to the client, so it can close # Tell pywebsocket we have sent a close frame to the client, so it can close
......
...@@ -12,9 +12,9 @@ def web_socket_transfer_data(request): ...@@ -12,9 +12,9 @@ def web_socket_transfer_data(request):
if line is None: if line is None:
return return
if line == '-': if line == '-':
data = '' data = b''
elif line == '--': elif line == '--':
data = 'X' data = b'X'
else: else:
code, reason = line.split(' ', 1) code, reason = line.split(' ', 1)
data = struct.pack('!H', int(code)) + reason.encode('utf-8') data = struct.pack('!H', int(code)) + reason.encode('utf-8')
......
...@@ -26,9 +26,8 @@ ...@@ -26,9 +26,8 @@
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import cgi
import json import json
from six.moves.urllib import parse
from mod_pywebsocket import msgutil from mod_pywebsocket import msgutil
connections = {} connections = {}
...@@ -43,7 +42,7 @@ def web_socket_transfer_data(request): ...@@ -43,7 +42,7 @@ def web_socket_transfer_data(request):
r = request.ws_resource.split('?', 1) r = request.ws_resource.split('?', 1)
if len(r) == 1: if len(r) == 1:
return return
param = cgi.parse_qs(r[1]) param = parse.parse_qs(r[1])
if 'p' not in param: if 'p' not in param:
return return
page_group = param['p'][0] page_group = param['p'][0]
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import logging import logging
import six
_GOODBYE_MESSAGE = u'Goodbye' _GOODBYE_MESSAGE = u'Goodbye'
...@@ -40,7 +41,7 @@ def web_socket_transfer_data(request): ...@@ -40,7 +41,7 @@ def web_socket_transfer_data(request):
line = request.ws_stream.receive_message() line = request.ws_stream.receive_message()
if line is None: if line is None:
return return
if isinstance(line, unicode): if isinstance(line, six.text_type):
request.ws_stream.send_message(line, binary=False) request.ws_stream.send_message(line, binary=False)
if line == _GOODBYE_MESSAGE: if line == _GOODBYE_MESSAGE:
return return
......
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys
import zlib
from mod_pywebsocket import common from mod_pywebsocket import common
from mod_pywebsocket import stream from mod_pywebsocket import stream
import zlib
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
...@@ -38,7 +40,7 @@ def web_socket_do_extra_handshake(request): ...@@ -38,7 +40,7 @@ def web_socket_do_extra_handshake(request):
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED,
-zlib.MAX_WBITS) -zlib.MAX_WBITS)
compressed_message = compress.compress('close message') compressed_message = compress.compress(b'close message')
compressed_message += compress.flush(zlib.Z_SYNC_FLUSH) compressed_message += compress.flush(zlib.Z_SYNC_FLUSH)
compressed_message = compressed_message[:-4] compressed_message = compressed_message[:-4]
header = stream.create_header( header = stream.create_header(
......
import cgi from six.moves.urllib import parse
import time import time
import threading import threading
...@@ -11,7 +11,7 @@ def web_socket_do_extra_handshake(request): ...@@ -11,7 +11,7 @@ def web_socket_do_extra_handshake(request):
query_string = request.ws_resource.split('?', 1) query_string = request.ws_resource.split('?', 1)
if len(query_string) == 1: if len(query_string) == 1:
return return
params = cgi.parse_qs(query_string[1]) params = parse.parse_qs(query_string[1])
mode = params['mode'][0] mode = params['mode'][0]
if mode == 'new_test': if mode == 'new_test':
new_test(request) new_test(request)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import codecs import codecs
import six
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
...@@ -15,7 +16,7 @@ def web_socket_transfer_data(request): ...@@ -15,7 +16,7 @@ def web_socket_transfer_data(request):
line = request.ws_stream.receive_message() line = request.ws_stream.receive_message()
if line is None: if line is None:
return return
if isinstance(line, unicode): if isinstance(line, six.text_type):
request.received_bytes += len(codecs.encode(line, 'utf-8')) request.received_bytes += len(codecs.encode(line, 'utf-8'))
else: else:
request.received_bytes += len(line) request.received_bytes += len(line)
......
...@@ -3,16 +3,16 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,16 +3,16 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
message = 'HTTP/1.1 101 Switching Protocols\r\n' message = (b'HTTP/1.1 101 Switching Protocols\r\n'
message += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
message += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'foo: bar, baz\r\n'
message += 'foo: bar, baz\r\n' b'foo: hoge\r\n'
message += 'foo: hoge\r\n' b'FOO: FUGA\r\n'
message += 'FOO: FUGA\r\n' b'xxx: yyy\r\n'
message += 'xxx: yyy\r\n' b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
message += '\r\n'
request.connection.write(message) request.connection.write(message)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from mod_pywebsocket import common, msgutil from mod_pywebsocket import msgutil
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
......
...@@ -16,4 +16,7 @@ def web_socket_do_extra_handshake(request): ...@@ -16,4 +16,7 @@ def web_socket_do_extra_handshake(request):
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
msgutil.send_message(request, json.dumps(dict(request.headers_in.items()))) # Since python 3 does not lowercase the dictionary key, manually lower all
# keys to maintain python 2/3 compatibility
lowered_dict = {header.lower(): value for header, value in request.headers_in.items()}
msgutil.send_message(request, json.dumps(lowered_dict))
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import six
_GOODBYE_MESSAGE = u'Goodbye' _GOODBYE_MESSAGE = u'Goodbye'
...@@ -39,7 +41,7 @@ def web_socket_transfer_data(request): ...@@ -39,7 +41,7 @@ def web_socket_transfer_data(request):
line = request.ws_stream.receive_message() line = request.ws_stream.receive_message()
if line is None: if line is None:
return return
if isinstance(line, unicode): if isinstance(line, six.text_type):
request.ws_stream.send_message(line, binary=False) request.ws_stream.send_message(line, binary=False)
if line == _GOODBYE_MESSAGE: if line == _GOODBYE_MESSAGE:
return return
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import six
_GOODBYE_MESSAGE = u'Goodbye' _GOODBYE_MESSAGE = u'Goodbye'
...@@ -39,7 +41,7 @@ def web_socket_transfer_data(request): ...@@ -39,7 +41,7 @@ def web_socket_transfer_data(request):
line = request.ws_stream.receive_message() line = request.ws_stream.receive_message()
if line is None: if line is None:
return return
if isinstance(line, unicode): if isinstance(line, six.text_type):
request.ws_stream.send_message(line, binary=False) request.ws_stream.send_message(line, binary=False)
if line == _GOODBYE_MESSAGE: if line == _GOODBYE_MESSAGE:
return return
......
...@@ -30,7 +30,7 @@ from mod_pywebsocket import msgutil ...@@ -30,7 +30,7 @@ from mod_pywebsocket import msgutil
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
request.connection.write('ThisWillCauseHandshakeError\r\n') request.connection.write(b'ThisWillCauseHandshakeError\r\n')
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
......
...@@ -3,13 +3,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,13 +3,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
message = 'HTTP/1.1 101 Switching Protocols\r\n' message = (b'HTTP/1.1 101 Switching Protocols\r\n'
message += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
message += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'Sec-WebSocket-Extensions: x-foo\r\n'
message += 'Sec-WebSocket-Extensions: x-foo\r\n' b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
message += '\r\n'
request.connection.write(message) request.connection.write(message)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -26,13 +26,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -26,13 +26,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
# This will cause the handshake to fail because it pushes the length of the # This will cause the handshake to fail because it pushes the length of the
# status line past 1024 characters # status line past 1024 characters
msg = '.' * 1024 msg = (b'%s'
msg += 'HTTP/1.1 101 Switching Protocols\r\n' b'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
msg += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'\r\n') % (b'.' * 1024, compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0])
msg += '\r\n'
request.connection.write(msg) request.connection.write(msg)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('abort the connection') raise handshake.AbortedByUserException('abort the connection')
......
...@@ -3,13 +3,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,13 +3,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
msg = 'HTTP/1.1 101 Switching Protocols\r\n' msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
msg += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'Sec-WebSocket-Protocol: MismatchProtocol\r\n'
msg += 'Sec-WebSocket-Protocol: MismatchProtocol\r\n' b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
msg += '\r\n'
request.connection.write(msg) request.connection.write(msg)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -3,15 +3,14 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,15 +3,14 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
msg = 'HTTP/1.1 101 Switching Protocols\r\n' msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
msg += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'Sec-WebSocket-Accept: XXXXthisiswrongXXXX\r\n'
msg += 'Sec-WebSocket-Accept: XXXXthisiswrongXXXX\r\n' b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
msg += '\r\n'
request.connection.write(msg) request.connection.write(msg)
print msg
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -3,14 +3,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,14 +3,13 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
msg = 'HTTP/1.1 101 Switching Protocols\r\n' msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
msg += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'Sec-WebSocket-Protocol: MatchProtocol\r\n'
msg += 'Sec-WebSocket-Protocol: MatchProtocol\r\n' b'Sec-WebSocket-Protocol: MismatchProtocol\r\n'
msg += 'Sec-WebSocket-Protocol: MismatchProtocol\r\n' b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
msg += '\r\n'
request.connection.write(msg) request.connection.write(msg)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -2,10 +2,7 @@ from mod_pywebsocket import handshake ...@@ -2,10 +2,7 @@ from mod_pywebsocket import handshake
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
message = 'HTTP/1.1 101 Switching Protocols\r\n' message = b'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n'
message += 'Upgrade: websocket\r\n'
message += 'Connection: Upgrade\r\n'
message += '\r\n'
request.connection.write(message) request.connection.write(message)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -3,14 +3,12 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,14 +3,12 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
msg = 'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Upgrade: websocket\r\n'
# Missing 'Connection: Upgrade\r\n' # Missing 'Connection: Upgrade\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'Upgrade: websocket\r\n'
msg += '\r\n' b'Sec-WebSocket-Accept: %s\r\n'
b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
request.connection.write(msg) request.connection.write(msg)
print msg
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -3,14 +3,12 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,14 +3,12 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
msg = 'HTTP/1.1 101 Switching Protocols\r\n'
# Missing 'Upgrade: websocket\r\n' # Missing 'Upgrade: websocket\r\n'
msg += 'Connection: Upgrade\r\n' msg = (b'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Connection: Upgrade\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'Sec-WebSocket-Accept: %s\r\n'
msg += '\r\n' b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
request.connection.write(msg) request.connection.write(msg)
print msg
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -3,12 +3,11 @@ from mod_pywebsocket.handshake.hybi import compute_accept ...@@ -3,12 +3,11 @@ from mod_pywebsocket.handshake.hybi import compute_accept
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
message = 'HTTP/1.1 101 Switching Protocols\r\n' message = (b'HTTP/1.1 101 Switching Protocols\r\n'
message += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
message += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
message += '\r\n'
request.connection.write(message) request.connection.write(message)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import division
import time import time
from mod_pywebsocket import stream from mod_pywebsocket import stream
from mod_pywebsocket.handshake.hybi import compute_accept from mod_pywebsocket.handshake.hybi import compute_accept
...@@ -33,18 +34,17 @@ def web_socket_do_extra_handshake(request): ...@@ -33,18 +34,17 @@ def web_socket_do_extra_handshake(request):
frame = stream.create_text_frame('\0Frame-contains-thirty-two-bytes') frame = stream.create_text_frame('\0Frame-contains-thirty-two-bytes')
msg = frame msg = frame
msg += 'HTTP/1.1 101 Switching Protocols\r\n' msg += (b'HTTP/1.1 101 Switching Protocols\r\n'
msg += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
msg += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept( b'Sec-WebSocket-Accept: %s\r\n'
request.headers_in['Sec-WebSocket-Key'])[0] b'\r\n') % compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0]
msg += '\r\n'
request.connection.write(msg) request.connection.write(msg)
# continue writing data until the client disconnects # continue writing data until the client disconnects
while True: while True:
time.sleep(1) time.sleep(1)
# write over 1024 bytes including the above handshake # write over 1024 bytes including the above handshake
numFrames = 1024 / len(frame) numFrames = 1024 // len(frame)
for i in range(0, numFrames): for i in range(0, numFrames):
request.connection.write(frame) request.connection.write(frame)
......
...@@ -2,9 +2,7 @@ from mod_pywebsocket import handshake ...@@ -2,9 +2,7 @@ from mod_pywebsocket import handshake
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
message = 'HTTP/1.1 401 Unauthorized\r\n' message = b'HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm="Access to staging site"\r\n\r\n'
message += 'WWW-Authenticate: Basic realm="Access to staging site"\r\n'
message += '\r\n'
request.connection.write(message) request.connection.write(message)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -2,11 +2,11 @@ from mod_pywebsocket import handshake ...@@ -2,11 +2,11 @@ from mod_pywebsocket import handshake
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
message = 'HTTP/1.1 101 Switching Protocols\r\n' message = (b'HTTP/1.1 101 Switching Protocols\r\n'
message += 'Upgrade: websocket\r\n' b'Upgrade: websocket\r\n'
message += 'Connection: Upgrade\r\n' b'Connection: Upgrade\r\n'
message += 'Sec-WebSocket-Accept: XXXXthisiswrongXXXX\r\n' b'Sec-WebSocket-Accept: XXXXthisiswrongXXXX\r\n'
message += '\r\n' b'\r\n')
request.connection.write(message) request.connection.write(message)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -7,8 +7,8 @@ def web_socket_do_extra_handshake(request): ...@@ -7,8 +7,8 @@ def web_socket_do_extra_handshake(request):
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
payload1 = 'Invalid continuation frame to be ignored.' payload1 = b'Invalid continuation frame to be ignored.'
payload2 = 'Valid frame after closing should be disposed.' payload2 = b'Valid frame after closing should be disposed.'
request.connection.write( request.connection.write(
stream.create_header(common.OPCODE_CONTINUATION, stream.create_header(common.OPCODE_CONTINUATION,
len(payload1), 1, 0, 0, 0, 0) + payload1) len(payload1), 1, 0, 0, 0, 0) + payload1)
......
...@@ -2,9 +2,9 @@ from mod_pywebsocket import handshake ...@@ -2,9 +2,9 @@ from mod_pywebsocket import handshake
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
msg = 'HTTP/1.1 101 WebSocket Protocol Handshake\r\n' msg = b'HTTP/1.1 101 WebSocket Protocol Handshake\r\n'
msg += ('p' * 1024) + '\r\n' msg += (b'p' * 1024) + b'\r\n'
msg += '\r\n' msg += b'\r\n'
request.connection.write(msg) request.connection.write(msg)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import urllib from six.moves.urllib import parse
from mod_pywebsocket import handshake from mod_pywebsocket import handshake
from mod_pywebsocket.handshake.hybi import compute_accept from mod_pywebsocket.handshake.hybi import compute_accept
...@@ -35,19 +35,16 @@ def web_socket_do_extra_handshake(request): ...@@ -35,19 +35,16 @@ def web_socket_do_extra_handshake(request):
resources = request.ws_resource.split('?', 1) resources = request.ws_resource.split('?', 1)
parameters = None parameters = None
if len(resources) == 2: if len(resources) == 2:
parameters = urllib.unquote(resources[1]) parameters = parse.unquote(resources[1])
message_parameters = (b'; %s\r\n' % parameters.encode('utf-8') if parameters else b'\r\n')
message = (b'HTTP/1.1 101 Switching Protocols\r\n'
b'Upgrade: websocket\r\n'
b'Connection: Upgrade\r\n'
b'Sec-WebSocket-Accept: %s\r\n'
b'Sec-WebSocket-Extensions: permessage-deflate'
b'%s\r\n') % (compute_accept(request.headers_in['Sec-WebSocket-Key'].encode('UTF-8'))[0], message_parameters)
message = 'HTTP/1.1 101 Switching Protocols\r\n'
message += 'Upgrade: websocket\r\n'
message += 'Connection: Upgrade\r\n'
message += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(
request.headers_in['Sec-WebSocket-Key'])[0]
message += 'Sec-WebSocket-Extensions: permessage-deflate'
if parameters:
message += '; %s\r\n' % parameters
else:
message += '\r\n'
message += '\r\n'
request.connection.write(message) request.connection.write(message)
# Prevents pywebsocket from sending its own handshake message. # Prevents pywebsocket from sending its own handshake message.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
......
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import urlparse from six.moves.urllib import parse
import zlib import zlib
from mod_pywebsocket import common, util from mod_pywebsocket import common
from mod_pywebsocket import util
from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor
from mod_pywebsocket.extensions import ExtensionProcessorInterface from mod_pywebsocket.extensions import ExtensionProcessorInterface
from mod_pywebsocket.common import ExtensionParameter from mod_pywebsocket.common import ExtensionParameter
...@@ -59,7 +60,7 @@ def web_socket_do_extra_handshake(request): ...@@ -59,7 +60,7 @@ def web_socket_do_extra_handshake(request):
r = request.ws_resource.split('?', 1) r = request.ws_resource.split('?', 1)
if len(r) == 1: if len(r) == 1:
return return
parameters = urlparse.parse_qs(r[1], keep_blank_values=True) parameters = parse.parse_qs(r[1], keep_blank_values=True)
if 'client_max_window_bits' in parameters: if 'client_max_window_bits' in parameters:
window_bits = int(parameters['client_max_window_bits'][0]) window_bits = int(parameters['client_max_window_bits'][0])
processor.set_client_max_window_bits(window_bits) processor.set_client_max_window_bits(window_bits)
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import urlparse
from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import urlparse import six
from six.moves.urllib import parse
from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor from mod_pywebsocket.extensions import PerMessageDeflateExtensionProcessor
from mod_pywebsocket.extensions import ExtensionProcessorInterface from mod_pywebsocket.extensions import ExtensionProcessorInterface
from mod_pywebsocket.common import ExtensionParameter from mod_pywebsocket.common import ExtensionParameter
...@@ -55,7 +57,7 @@ def web_socket_do_extra_handshake(request): ...@@ -55,7 +57,7 @@ def web_socket_do_extra_handshake(request):
r = request.ws_resource.split('?', 1) r = request.ws_resource.split('?', 1)
if len(r) == 1: if len(r) == 1:
return return
parameters = urlparse.parse_qs(r[1], keep_blank_values=True) parameters = parse.parse_qs(r[1], keep_blank_values=True)
if 'client_max_window_bits' in parameters: if 'client_max_window_bits' in parameters:
window_bits = int(parameters['client_max_window_bits'][0]) window_bits = int(parameters['client_max_window_bits'][0])
processor.set_client_max_window_bits(window_bits) processor.set_client_max_window_bits(window_bits)
...@@ -72,7 +74,7 @@ def web_socket_transfer_data(request): ...@@ -72,7 +74,7 @@ def web_socket_transfer_data(request):
line = request.ws_stream.receive_message() line = request.ws_stream.receive_message()
if line is None: if line is None:
return return
if isinstance(line, unicode): if isinstance(line, six.text_type):
if processor: if processor:
if line == _ENABLE_MESSAGE: if line == _ENABLE_MESSAGE:
processor.enable_outgoing_compression() processor.enable_outgoing_compression()
......
import cgi from six.moves.urllib import parse
from mod_pywebsocket import common from mod_pywebsocket import common
from mod_pywebsocket import msgutil from mod_pywebsocket import msgutil
...@@ -11,7 +11,7 @@ def web_socket_transfer_data(request): ...@@ -11,7 +11,7 @@ def web_socket_transfer_data(request):
send_payload = '' send_payload = ''
r = request.ws_resource.split('?', 1) r = request.ws_resource.split('?', 1)
if len(r) == 2: if len(r) == 2:
params = cgi.parse_qs(r[1]) params = parse.parse_qs(r[1])
if 'payload' in params: if 'payload' in params:
send_payload = params['payload'][0] send_payload = params['payload'][0]
...@@ -21,8 +21,8 @@ def web_socket_transfer_data(request): ...@@ -21,8 +21,8 @@ def web_socket_transfer_data(request):
# client. # client.
opcode, recv_payload, final, reserved1, reserved2, reserved3 = \ opcode, recv_payload, final, reserved1, reserved2, reserved3 = \
request.ws_stream._receive_frame() request.ws_stream._receive_frame()
if (opcode == common.OPCODE_PONG and recv_payload == send_payload and if (opcode == common.OPCODE_PONG and recv_payload.decode('UTF-8') == send_payload and final and not reserved1 and not reserved2
final and not reserved1 and not reserved2 and not reserved3): and not reserved3):
msgutil.send_message(request, 'PASS') msgutil.send_message(request, 'PASS')
else: else:
msgutil.send_message( msgutil.send_message(
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import cgi from six.moves.urllib import parse
from mod_pywebsocket import msgutil from mod_pywebsocket import msgutil
...@@ -34,7 +34,7 @@ def web_socket_do_extra_handshake(request): ...@@ -34,7 +34,7 @@ def web_socket_do_extra_handshake(request):
r = request.ws_resource.split('?', 1) r = request.ws_resource.split('?', 1)
if len(r) == 1: if len(r) == 1:
return return
param = cgi.parse_qs(r[1]) param = parse.parse_qs(r[1])
if 'protocol' in param: if 'protocol' in param:
request.ws_protocol = param['protocol'][0] request.ws_protocol = param['protocol'][0]
......
...@@ -3,6 +3,6 @@ def web_socket_do_extra_handshake(request): ...@@ -3,6 +3,6 @@ def web_socket_do_extra_handshake(request):
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
request.ws_stream._send_pong("{payload: 'yes'}") request.ws_stream._send_pong(b"{payload: 'yes'}")
request.ws_stream.send_message('sent pong') request.ws_stream.send_message('sent pong')
line = request.ws_stream.receive_message() line = request.ws_stream.receive_message()
import re import re
from mod_pywebsocket import common from mod_pywebsocket import common
from mod_pywebsocket import stream from mod_pywebsocket import stream
from mod_pywebsocket.extensions import DeflateFrameExtensionProcessor from mod_pywebsocket import msgutil
bit = 0 bit = 0
def _get_deflate_frame_extension_processor(request):
for extension_processor in request.ws_extension_processors:
if isinstance(extension_processor, DeflateFrameExtensionProcessor):
return extension_processor
return None
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
match = re.search(r'\?compressed=(true|false)&bitNumber=(\d)$', match = re.search(r'\?compressed=(true|false)&bitNumber=(\d)$',
request.ws_resource) request.ws_resource)
...@@ -24,18 +17,11 @@ def web_socket_do_extra_handshake(request): ...@@ -24,18 +17,11 @@ def web_socket_do_extra_handshake(request):
global bit global bit
compressed = match.group(1) compressed = match.group(1)
bit = int(match.group(2)) bit = int(match.group(2))
if compressed == 'false': request.ws_extension_processors = [] # using no extension response
request.ws_extension_processors = [] # using no extension response
else:
processor = _get_deflate_frame_extension_processor(request)
if processor is None:
request.ws_extension_processors = [] # using no extension response
else:
request.ws_extension_processors = [processor] # avoid conflict
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
text = 'This message should be ignored.' text = b'This message should be ignored.'
opcode = common.OPCODE_TEXT opcode = common.OPCODE_TEXT
if bit == 1: if bit == 1:
frame = stream.create_header(opcode, len(text), 1, 1, 0, 0, 0) + text frame = stream.create_header(opcode, len(text), 1, 1, 0, 0, 0) + text
......
...@@ -16,6 +16,6 @@ def web_socket_transfer_data(request): ...@@ -16,6 +16,6 @@ def web_socket_transfer_data(request):
return return
opcode = int(match.group(1)) opcode = int(match.group(1))
payload = 'This text should be ignored. (opcode = %d)' % opcode payload = b'This text should be ignored. (opcode = %d)' % opcode
request.connection.write( request.connection.write(
stream.create_header(opcode, len(payload), 1, 0, 0, 0, 0) + payload) stream.create_header(opcode, len(payload), 1, 0, 0, 0, 0) + payload)
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import urlparse from six.moves.urllib import parse
def web_socket_do_extra_handshake(request): def web_socket_do_extra_handshake(request):
query = urlparse.urlparse(request.uri)[4] query = parse.urlparse(request.uri)[4]
max_age = '' max_age = ''
if 'clear' in urlparse.parse_qs(query): if 'clear' in parse.parse_qs(query):
max_age = '; Max-Age=0' max_age = '; Max-Age=0'
cookie_values = [ cookie_values = [
'ws-domain-local-ip=1; Domain=127.0.0.1' + max_age, 'ws-domain-local-ip=1; Domain=127.0.0.1' + max_age,
......
...@@ -37,7 +37,7 @@ def web_socket_transfer_data(request): ...@@ -37,7 +37,7 @@ def web_socket_transfer_data(request):
# Send a masked close frame. Clients should be able to handle this frame # Send a masked close frame. Clients should be able to handle this frame
# and the WebSocket object should be closed cleanly. # and the WebSocket object should be closed cleanly.
request.connection.write(stream.create_close_frame('', mask=False)) request.connection.write(stream.create_close_frame(b'', mask=False))
# Prevents pywebsocket from starting its own closing handshake. # Prevents pywebsocket from starting its own closing handshake.
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
import six
from mod_pywebsocket import handshake from mod_pywebsocket import handshake
from mod_pywebsocket import msgutil from mod_pywebsocket import msgutil
...@@ -14,5 +16,5 @@ def web_socket_transfer_data(request): ...@@ -14,5 +16,5 @@ def web_socket_transfer_data(request):
for expected in (u'1', u'2', u'3'): for expected in (u'1', u'2', u'3'):
message = msgutil.receive_message(request) message = msgutil.receive_message(request)
if type(message) != unicode or message != expected: if not isinstance(message, six.text_type) or message != expected:
raise handshake.AbortedByUserException('Abort the connection') raise handshake.AbortedByUserException('Abort the connection')
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import cgi from six.moves.urllib import parse
from mod_pywebsocket import msgutil from mod_pywebsocket import msgutil
...@@ -34,7 +34,7 @@ def web_socket_do_extra_handshake(request): ...@@ -34,7 +34,7 @@ def web_socket_do_extra_handshake(request):
r = request.ws_resource.split('?', 1) r = request.ws_resource.split('?', 1)
if len(r) == 1: if len(r) == 1:
return return
param = cgi.parse_qs(r[1]) param = parse.parse_qs(r[1])
if 'protocol' in param: if 'protocol' in param:
request.ws_protocol = param['protocol'][0] request.ws_protocol = param['protocol'][0]
......
...@@ -7,9 +7,9 @@ def web_socket_do_extra_handshake(request): ...@@ -7,9 +7,9 @@ def web_socket_do_extra_handshake(request):
def web_socket_transfer_data(request): def web_socket_transfer_data(request):
payload1 = 'This first text should be received.' payload1 = b'This first text should be received.'
payload2 = 'This second text ' payload2 = b'This second text '
payload3 = 'should be received, too.' payload3 = b'should be received, too.'
# send '' # send ''
request.connection.write( request.connection.write(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment