Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wspy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
wspy
Commits
a6952f5b
Commit
a6952f5b
authored
Nov 10, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed InvalidRequest to HandshakeError
parent
26c511bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
9 deletions
+13
-9
exceptions.py
exceptions.py
+1
-1
server.py
server.py
+2
-2
websocket.py
websocket.py
+10
-6
No files found.
exceptions.py
View file @
a6952f5b
...
...
@@ -2,7 +2,7 @@ class SocketClosed(Exception):
pass
class
InvalidRequest
(
ValueError
):
class
HandshakeError
(
Exception
):
pass
...
...
server.py
View file @
a6952f5b
...
...
@@ -6,7 +6,7 @@ from threading import Thread
from
websocket
import
websocket
from
connection
import
Connection
from
frame
import
CLOSE_NORMAL
from
exceptions
import
InvalidRequest
from
exceptions
import
HandshakeError
class
Server
(
object
):
...
...
@@ -36,7 +36,7 @@ class Server(object):
thread
=
Thread
(
target
=
client
.
receive_forever
)
thread
.
daemon
=
True
thread
.
start
()
except
InvalidRequest
as
e
:
except
HandshakeError
as
e
:
logging
.
error
(
'Invalid request: %s'
,
e
.
message
)
except
KeyboardInterrupt
:
logging
.
info
(
'Received interrupt, stopping server...'
)
...
...
websocket.py
View file @
a6952f5b
...
...
@@ -3,7 +3,7 @@ import socket
from
hashlib
import
sha1
from
frame
import
receive_frame
from
exceptions
import
InvalidRequest
from
exceptions
import
HandshakeError
WS_GUID
=
'258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
...
...
@@ -57,7 +57,7 @@ class websocket(object):
"""
Equivalent to socket.accept(), but transforms the socket into a
websocket instance and sends a server handshake (after receiving a
client handshake). Note that the handshake may raise an
InvalidRequest
client handshake). Note that the handshake may raise an
HandshakeError
exception.
"""
client
,
address
=
self
.
sock
.
accept
()
...
...
@@ -102,8 +102,8 @@ class websocket(object):
def
server_handshake
(
self
):
"""
Execute a handshake as the server end point of the socket. If the HTTP
request headers sent by the client are invalid, a
n InvalidRequest
exception
is raised.
request headers sent by the client are invalid, a
HandshakeError
is raised.
"""
raw_headers
=
self
.
sock
.
recv
(
512
).
decode
(
'utf-8'
,
'ignore'
)
...
...
@@ -119,13 +119,13 @@ class websocket(object):
for
name
in
(
'Host'
,
'Upgrade'
,
'Connection'
,
'Sec-WebSocket-Key'
,
'Origin'
,
'Sec-WebSocket-Version'
):
if
name
not
in
header_names
:
raise
InvalidRequest
(
'missing "%s" header'
%
name
)
raise
HandshakeError
(
'missing "%s" header'
%
name
)
# Check WebSocket version used by client
version
=
header
(
'Sec-WebSocket-Version'
)
if
version
!=
WS_VERSION
:
raise
InvalidRequest
(
'WebSocket version %s requested (only %s '
raise
HandshakeError
(
'WebSocket version %s requested (only %s '
'is supported)'
%
(
version
,
WS_VERSION
))
# Only supported protocols are returned
...
...
@@ -160,5 +160,9 @@ class websocket(object):
self
.
sock
.
send
(
shake
+
'
\
r
\
n
'
)
def
client_handshake
(
self
):
"""
Execute a handshake as the client end point of the socket. May raise a
HandshakeError if the server response is invalid.
"""
# TODO: implement HTTP request headers for client handshake
raise
NotImplementedError
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment