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
Show 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
...
@@ -87,9 +87,9 @@ class Frame(object):
...
@@ -87,9 +87,9 @@ class Frame(object):
| Payload Data continued ... |
| Payload Data continued ... |
+---------------------------------------------------------------+
+---------------------------------------------------------------+
"""
"""
header
=
struct
.
pack
(
'!B'
,
(
self
.
final
<<
7
)
|
(
self
.
rsv1
<<
6
)
|
header
=
struct
.
pack
(
'!B'
,
(
self
.
final
<<
7
)
|
(
self
.
rsv1
<<
6
)
(
self
.
rsv2
<<
5
)
|
(
self
.
rsv3
<<
4
)
|
self
.
opcode
)
|
(
self
.
rsv2
<<
5
)
|
(
self
.
rsv3
<<
4
)
|
(
self
.
opcode
&
0xf
))
mask
=
bool
(
self
.
masking_key
)
<<
7
mask
=
bool
(
self
.
masking_key
)
<<
7
payload_len
=
len
(
self
.
payload
)
payload_len
=
len
(
self
.
payload
)
...
...
websocket.py
View file @
d232216d
import
re
import
re
import
socket
import
socket
from
hashlib
import
sha1
from
hashlib
import
sha1
from
base64
import
b64encode
from
frame
import
receive_frame
from
frame
import
receive_frame
from
errors
import
HandshakeError
from
errors
import
HandshakeError
...
@@ -81,6 +82,7 @@ class websocket(object):
...
@@ -81,6 +82,7 @@ class websocket(object):
Send a number of frames.
Send a number of frames.
"""
"""
for
frame
in
args
:
for
frame
in
args
:
#print 'send frame:', frame, 'to %s:%d' % self.sock.getpeername()
self
.
sock
.
sendall
(
frame
.
pack
())
self
.
sock
.
sendall
(
frame
.
pack
())
def
recv
(
self
):
def
recv
(
self
):
...
@@ -89,6 +91,7 @@ class websocket(object):
...
@@ -89,6 +91,7 @@ class websocket(object):
frame.
frame.
"""
"""
frame
=
receive_frame
(
self
.
sock
)
frame
=
receive_frame
(
self
.
sock
)
#print 'receive frame:', frame, 'from %s:%d' % self.sock.getpeername()
return
frame
return
frame
def
recvn
(
self
,
n
):
def
recvn
(
self
,
n
):
...
@@ -123,7 +126,7 @@ class websocket(object):
...
@@ -123,7 +126,7 @@ class websocket(object):
# request must be HTTP (at least 1.1) GET request, find the location
# 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
)
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
]
header_names
=
[
name
for
name
,
value
in
headers
]
def
header
(
name
):
def
header
(
name
):
...
@@ -153,8 +156,8 @@ class websocket(object):
...
@@ -153,8 +156,8 @@ class websocket(object):
extensions
=
[
e
for
e
in
extensions
if
e
in
self
.
extensions
]
extensions
=
[
e
for
e
in
extensions
if
e
in
self
.
extensions
]
# Encode acceptation key using the WebSocket GUID
# Encode acceptation key using the WebSocket GUID
key
=
header
(
'Sec-WebSocket-Key'
)
key
=
header
(
'Sec-WebSocket-Key'
)
.
strip
()
accept
=
sha1
(
key
+
WS_GUID
).
digest
().
encode
(
'base64'
)
accept
=
b64encode
(
sha1
(
key
+
WS_GUID
).
digest
()
)
# Construct HTTP response header
# Construct HTTP response header
shake
=
'HTTP/1.1 101 Web Socket Protocol Handshake
\
r
\
n
'
shake
=
'HTTP/1.1 101 Web Socket Protocol Handshake
\
r
\
n
'
...
@@ -171,7 +174,7 @@ class websocket(object):
...
@@ -171,7 +174,7 @@ class websocket(object):
if
extensions
:
if
extensions
:
shake
+=
'Sec-WebSocket-Extensions: %s
\
r
\
n
'
%
', '
.
join
(
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
):
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