Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
nginx-push-stream-module
Commits
84739f70
Commit
84739f70
authored
Jan 01, 2016
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support to fragmented frames on websocket connection
parent
6b52c936
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
277 additions
and
48 deletions
+277
-48
ngx_http_push_stream_module.h
include/ngx_http_push_stream_module.h
+4
-1
websocket_spec.rb
misc/spec/subscriber/websocket_spec.rb
+167
-16
ngx_http_push_stream_module_websocket.c
src/ngx_http_push_stream_module_websocket.c
+106
-31
No files found.
include/ngx_http_push_stream_module.h
View file @
84739f70
...
@@ -224,8 +224,11 @@ typedef struct {
...
@@ -224,8 +224,11 @@ typedef struct {
uint64_t
payload_len
;
uint64_t
payload_len
;
u_char
header
[
8
];
u_char
header
[
8
];
u_char
*
payload
;
u_char
*
payload
;
u_char
*
last
;
ngx_uint_t
step
;
ngx_uint_t
step
;
ngx_buf_t
buf
;
ngx_str_t
consolidated
;
unsigned
char
fragmented
:
1
;
unsigned
char
last_fragment
:
1
;
}
ngx_http_push_stream_frame_t
;
}
ngx_http_push_stream_frame_t
;
typedef
struct
{
typedef
struct
{
...
...
misc/spec/subscriber/websocket_spec.rb
View file @
84739f70
...
@@ -400,22 +400,8 @@ describe "Subscriber WebSocket" do
...
@@ -400,22 +400,8 @@ describe "Subscriber WebSocket" do
channel
=
'ch_test_publish_message_low_bitrate'
channel
=
'ch_test_publish_message_low_bitrate'
configuration
=
config
.
merge
({
configuration
=
config
.
merge
({
:shared_memory_size
=>
'15m'
,
shared_memory_size:
'15m'
,
:message_template
=>
'{\"channel\":\"~channel~\", \"message\":\"~text~\"}'
,
message_template:
'{\"channel\":\"~channel~\", \"message\":\"~text~\"}'
,
:extra_location
=>
%q{
location ~ /ws/(.*)? {
# activate websocket mode for this location
push_stream_subscriber websocket;
# positional channel path
push_stream_channels_path $1;
# allow subscriber to publish
push_stream_websocket_allow_publish on;
# store messages
push_stream_store_messages on;
}
}
})
})
count
=
0
count
=
0
...
@@ -734,4 +720,169 @@ describe "Subscriber WebSocket" do
...
@@ -734,4 +720,169 @@ describe "Subscriber WebSocket" do
end
end
end
end
end
end
it
"should accept unmasked frames"
do
channel
=
'ch_test_publish_unmasked_frames'
configuration
=
config
.
merge
({
shared_memory_size:
'15m'
,
message_template:
'{\"channel\":\"~channel~\", \"message\":\"~text~\"}'
,
subscriber_mode:
'long-polling'
,
})
nginx_run_server
(
configuration
,
timeout:
60
)
do
|
conf
|
EventMachine
.
run
do
frame
=
"%c%c%c%c%c%c%c"
%
[
0x81
,
0x05
,
0x48
,
0x65
,
0x6c
,
0x6c
,
0x6f
]
#send 'hello' frame
request
=
"GET /ws/
#{
channel
}
HTTP/1.0
\r\n
Connection: Upgrade
\r\n
Sec-WebSocket-Key: /mQoZf6pRiv8+6o72GncLQ==
\r\n
Upgrade: websocket
\r\n
Sec-WebSocket-Version: 8
\r\n
"
socket
=
open_socket
(
nginx_host
,
nginx_port
)
socket
.
print
(
"
#{
request
}
\r\n
"
)
headers
,
body
=
read_response_on_socket
(
socket
)
socket
.
print
(
frame
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_unmasked_frames", "message":"Hello"}]
)
socket
.
close
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'.b1'
).
get
:timeout
=>
30
sub
.
callback
do
expect
(
sub
).
to
be_http_status
(
200
)
response
=
JSON
.
parse
(
sub
.
response
)
expect
(
response
[
"channel"
].
to_s
).
to
eql
(
channel
)
expect
(
response
[
"message"
]).
to
eql
(
"Hello"
)
EventMachine
.
stop
end
end
end
end
it
"should accept masked frames"
do
channel
=
'ch_test_publish_masked_frames'
configuration
=
config
.
merge
({
shared_memory_size:
'15m'
,
message_template:
'{\"channel\":\"~channel~\", \"message\":\"~text~\"}'
,
subscriber_mode:
'long-polling'
,
})
nginx_run_server
(
configuration
,
timeout:
60
)
do
|
conf
|
EventMachine
.
run
do
frame
=
"%c%c%c%c%c%c%c%c%c%c%c"
%
[
0x81
,
0x85
,
0x37
,
0xfa
,
0x21
,
0x3d
,
0x7f
,
0x9f
,
0x4d
,
0x51
,
0x58
]
#send 'hello' frame
request
=
"GET /ws/
#{
channel
}
HTTP/1.0
\r\n
Connection: Upgrade
\r\n
Sec-WebSocket-Key: /mQoZf6pRiv8+6o72GncLQ==
\r\n
Upgrade: websocket
\r\n
Sec-WebSocket-Version: 8
\r\n
"
socket
=
open_socket
(
nginx_host
,
nginx_port
)
socket
.
print
(
"
#{
request
}
\r\n
"
)
headers
,
body
=
read_response_on_socket
(
socket
)
socket
.
print
(
frame
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_masked_frames", "message":"Hello"}]
)
socket
.
close
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'.b1'
).
get
:timeout
=>
30
sub
.
callback
do
expect
(
sub
).
to
be_http_status
(
200
)
response
=
JSON
.
parse
(
sub
.
response
)
expect
(
response
[
"channel"
].
to_s
).
to
eql
(
channel
)
expect
(
response
[
"message"
]).
to
eql
(
"Hello"
)
EventMachine
.
stop
end
end
end
end
it
"should accept fragmented unmasked frames"
do
channel
=
'ch_test_publish_fragmented_unmasked_frames'
configuration
=
config
.
merge
({
shared_memory_size:
'15m'
,
message_template:
'{\"channel\":\"~channel~\", \"message\":\"~text~\"}'
,
subscriber_mode:
'long-polling'
,
})
nginx_run_server
(
configuration
,
timeout:
60
)
do
|
conf
|
EventMachine
.
run
do
frame_part1
=
"%c%c%c%c%c"
%
[
0x01
,
0x03
,
0x48
,
0x65
,
0x6c
]
#send 'Hel' frame
frame_part2
=
"%c%c%c%c"
%
[
0x80
,
0x02
,
0x6c
,
0x6f
]
#send 'lo' frame
request
=
"GET /ws/
#{
channel
}
HTTP/1.0
\r\n
Connection: Upgrade
\r\n
Sec-WebSocket-Key: /mQoZf6pRiv8+6o72GncLQ==
\r\n
Upgrade: websocket
\r\n
Sec-WebSocket-Version: 8
\r\n
"
socket
=
open_socket
(
nginx_host
,
nginx_port
)
socket
.
print
(
"
#{
request
}
\r\n
"
)
headers
,
body
=
read_response_on_socket
(
socket
)
socket
.
print
(
frame_part1
)
socket
.
print
(
frame_part2
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_fragmented_unmasked_frames", "message":"Hello"}]
)
socket
.
close
sub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
+
'.b1'
).
get
:timeout
=>
30
sub
.
callback
do
expect
(
sub
).
to
be_http_status
(
200
)
response
=
JSON
.
parse
(
sub
.
response
)
expect
(
response
[
"channel"
].
to_s
).
to
eql
(
channel
)
expect
(
response
[
"message"
]).
to
eql
(
"Hello"
)
EventMachine
.
stop
end
end
end
end
it
"should accept all kinds of frames mixed"
do
channel
=
'ch_test_publish_frames_mixed'
configuration
=
config
.
merge
({
shared_memory_size:
'15m'
,
message_template:
'{\"channel\":\"~channel~\", \"message\":\"~text~\"}'
,
})
nginx_run_server
(
configuration
,
timeout:
60
)
do
|
conf
|
frame_unmasked
=
"%c%c%c%c%c%c%c"
%
[
0x81
,
0x05
,
0x48
,
0x65
,
0x6c
,
0x6c
,
0x6f
]
#send 'hello' frame
frame_masked
=
"%c%c%c%c%c%c%c%c%c%c%c"
%
[
0x81
,
0x85
,
0x37
,
0xfa
,
0x21
,
0x3d
,
0x7f
,
0x9f
,
0x4d
,
0x51
,
0x58
]
#send 'hello' frame
frame_part1
=
"%c%c%c%c%c"
%
[
0x01
,
0x03
,
0x48
,
0x65
,
0x6c
]
#send 'Hel' frame
frame_part2
=
"%c%c%c%c"
%
[
0x80
,
0x02
,
0x6c
,
0x6f
]
#send 'lo' frame
request
=
"GET /ws/
#{
channel
}
HTTP/1.0
\r\n
Connection: Upgrade
\r\n
Sec-WebSocket-Key: /mQoZf6pRiv8+6o72GncLQ==
\r\n
Upgrade: websocket
\r\n
Sec-WebSocket-Version: 8
\r\n
"
socket
=
open_socket
(
nginx_host
,
nginx_port
)
socket
.
print
(
"
#{
request
}
\r\n
"
)
headers
,
body
=
read_response_on_socket
(
socket
)
socket
.
print
(
frame_unmasked
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
print
(
frame_masked
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
print
(
frame_part1
)
socket
.
print
(
frame_part2
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
print
(
frame_masked
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
print
(
frame_unmasked
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
print
(
frame_part1
)
socket
.
print
(
frame_part2
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
print
(
frame_unmasked
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
print
(
frame_masked
)
body
,
dummy
=
read_response_on_socket
(
socket
,
"llo"
)
expect
(
body
).
to
include
(
%[{"channel":"ch_test_publish_frames_mixed", "message":"Hello"}]
)
socket
.
close
end
end
end
end
src/ngx_http_push_stream_module_websocket.c
View file @
84739f70
This diff is collapsed.
Click to expand it.
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