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
d232216d
Commit
d232216d
authored
Jul 25, 2013
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed handshake error (base64 encoding bug)
parent
85101b27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
frame.py
frame.py
+4
-4
websocket.py
websocket.py
+7
-4
No files found.
frame.py
View file @
d232216d
...
...
@@ -55,7 +55,7 @@ class Frame(object):
if
mask
:
masking_key
=
urandom
(
4
)
if
len
(
masking_key
)
not
in
(
0
,
4
):
if
len
(
masking_key
)
not
in
(
0
,
4
):
raise
ValueError
(
'invalid masking key "%s"'
%
masking_key
)
self
.
final
=
final
...
...
@@ -87,9 +87,9 @@ class Frame(object):
| Payload Data continued ... |
+---------------------------------------------------------------+
"""
header
=
struct
.
pack
(
'!B'
,
(
self
.
final
<<
7
)
|
(
self
.
rsv1
<<
6
)
|
(
self
.
rsv2
<<
5
)
|
(
self
.
rsv3
<<
4
)
|
self
.
opcode
)
header
=
struct
.
pack
(
'!B'
,
(
self
.
final
<<
7
)
|
(
self
.
rsv1
<<
6
)
|
(
self
.
rsv2
<<
5
)
|
(
self
.
rsv3
<<
4
)
|
(
self
.
opcode
&
0xf
))
mask
=
bool
(
self
.
masking_key
)
<<
7
payload_len
=
len
(
self
.
payload
)
...
...
websocket.py
View file @
d232216d
import
re
import
socket
from
hashlib
import
sha1
from
base64
import
b64encode
from
frame
import
receive_frame
from
errors
import
HandshakeError
...
...
@@ -81,6 +82,7 @@ class websocket(object):
Send a number of frames.
"""
for
frame
in
args
:
#print 'send frame:', frame, 'to %s:%d' % self.sock.getpeername()
self
.
sock
.
sendall
(
frame
.
pack
())
def
recv
(
self
):
...
...
@@ -89,6 +91,7 @@ class websocket(object):
frame.
"""
frame
=
receive_frame
(
self
.
sock
)
#print 'receive frame:', frame, 'from %s:%d' % self.sock.getpeername()
return
frame
def
recvn
(
self
,
n
):
...
...
@@ -123,7 +126,7 @@ class websocket(object):
# request must be HTTP (at least 1.1) GET request, find the location
location
=
re
.
search
(
r'^GET (.*) HTTP/1.1\r\n'
,
raw_headers
).
group
(
1
)
headers
=
re
.
findall
(
r'(.*?): (.*?)\r\n'
,
raw_headers
)
headers
=
re
.
findall
(
r'(.*?):
?
(.*?)\r\n'
,
raw_headers
)
header_names
=
[
name
for
name
,
value
in
headers
]
def
header
(
name
):
...
...
@@ -153,8 +156,8 @@ class websocket(object):
extensions
=
[
e
for
e
in
extensions
if
e
in
self
.
extensions
]
# Encode acceptation key using the WebSocket GUID
key
=
header
(
'Sec-WebSocket-Key'
)
accept
=
sha1
(
key
+
WS_GUID
).
digest
().
encode
(
'base64'
)
key
=
header
(
'Sec-WebSocket-Key'
)
.
strip
()
accept
=
b64encode
(
sha1
(
key
+
WS_GUID
).
digest
()
)
# Construct HTTP response header
shake
=
'HTTP/1.1 101 Web Socket Protocol Handshake
\
r
\
n
'
...
...
@@ -171,7 +174,7 @@ class websocket(object):
if
extensions
:
shake
+=
'Sec-WebSocket-Extensions: %s
\
r
\
n
'
%
', '
.
join
(
extensions
)
self
.
sock
.
send
(
shake
+
'
\
r
\
n
'
)
self
.
sock
.
send
all
(
shake
+
'
\
r
\
n
'
)
def
client_handshake
(
self
):
"""
...
...
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