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
bbc74d46
Commit
bbc74d46
authored
Jul 06, 2015
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return a PONG frame when the client send a PING
parent
9bce6069
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
8 deletions
+44
-8
ngx_http_push_stream_module.h
include/ngx_http_push_stream_module.h
+2
-1
websocket_spec.rb
misc/spec/subscriber/websocket_spec.rb
+33
-3
ngx_http_push_stream_module_websocket.c
src/ngx_http_push_stream_module_websocket.c
+9
-4
No files found.
include/ngx_http_push_stream_module.h
View file @
bbc74d46
...
...
@@ -402,11 +402,12 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_MODE_WEBSOCKET = ngx_string("webs
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_TEXT_OPCODE 0x1
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_CLOSE_OPCODE 0x8
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_OPCODE 0x9
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_P
0
NG_OPCODE 0xA
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_P
O
NG_OPCODE 0xA
static
const
u_char
NGX_HTTP_PUSH_STREAM_WEBSOCKET_TEXT_LAST_FRAME_BYTE
=
NGX_HTTP_PUSH_STREAM_WEBSOCKET_TEXT_OPCODE
|
(
NGX_HTTP_PUSH_STREAM_WEBSOCKET_LAST_FRAME
<<
4
);
static
const
u_char
NGX_HTTP_PUSH_STREAM_WEBSOCKET_CLOSE_LAST_FRAME_BYTE
[]
=
{
NGX_HTTP_PUSH_STREAM_WEBSOCKET_CLOSE_OPCODE
|
(
NGX_HTTP_PUSH_STREAM_WEBSOCKET_LAST_FRAME
<<
4
),
0x00
};
static
const
u_char
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_LAST_FRAME_BYTE
[]
=
{
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_OPCODE
|
(
NGX_HTTP_PUSH_STREAM_WEBSOCKET_LAST_FRAME
<<
4
),
0x00
};
static
const
u_char
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PONG_LAST_FRAME_BYTE
[]
=
{
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PONG_OPCODE
|
(
NGX_HTTP_PUSH_STREAM_WEBSOCKET_LAST_FRAME
<<
4
),
0x00
};
static
const
u_char
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PAYLOAD_LEN_16_BYTE
=
126
;
static
const
u_char
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PAYLOAD_LEN_64_BYTE
=
127
;
...
...
misc/spec/subscriber/websocket_spec.rb
View file @
bbc74d46
...
...
@@ -176,7 +176,7 @@ describe "Subscriber WebSocket" do
end
end
it
"should
receive ping frame
"
do
it
"should
send a ping frame to client
"
do
channel
=
'ch_test_receive_ping_frame'
request
=
"GET /ws/
#{
channel
}
.b1 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
"
...
...
@@ -190,7 +190,7 @@ describe "Subscriber WebSocket" do
end
end
it
"should
receive close frame
"
do
it
"should
send a close frame to client
"
do
channel
=
'ch_test_receive_close_frame'
request
=
"GET /ws/
#{
channel
}
.b1 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
"
...
...
@@ -204,7 +204,7 @@ describe "Subscriber WebSocket" do
end
end
it
"should
receive
explain message on close frame"
do
it
"should
send a
explain message on close frame"
do
channel
=
'ch_test_receive_explain_message_close_frame'
request
=
"GET /ws/
#{
channel
}
.b1 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
"
...
...
@@ -453,6 +453,36 @@ describe "Subscriber WebSocket" do
end
end
it
"should accept ping message and return a pong frame"
do
channel
=
'ch_test_accept_ping_message'
frame
=
"%c%c%c%c%c%c%c"
%
[
0x89
,
0x05
,
0x48
,
0x65
,
0x6c
,
0x6c
,
0x6f
]
#send 'ping' frame with message
request
=
"GET /ws/
#{
channel
}
.b1 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
"
nginx_run_server
(
config
)
do
|
conf
|
socket
=
open_socket
(
nginx_host
,
nginx_port
)
socket
.
print
(
"
#{
request
}
\r\n
"
)
headers
,
body
=
read_response_on_socket
(
socket
)
socket
.
print
(
frame
)
body
,
_
=
read_response_on_socket
(
socket
)
expect
(
body
).
to
eql
(
"
\x8A\x00
"
)
EventMachine
.
run
do
pub
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats?id='
+
channel
.
to_s
).
get
:timeout
=>
30
pub
.
callback
do
socket
.
close
expect
(
pub
).
to
be_http_status
(
200
).
with_body
response
=
JSON
.
parse
(
pub
.
response
)
expect
(
response
[
"channel"
].
to_s
).
to
eql
(
channel
)
expect
(
response
[
"published_messages"
].
to_i
).
to
eql
(
0
)
expect
(
response
[
"stored_messages"
].
to_i
).
to
eql
(
0
)
expect
(
response
[
"subscribers"
].
to_i
).
to
eql
(
1
)
EventMachine
.
stop
end
end
end
end
it
"should accept pong message"
do
channel
=
'ch_test_accept_pong_message'
frame
=
"%c%c%c%c%c%c"
%
[
0x8A
,
0x80
,
0xBD
,
0xD0
,
0xE5
,
0x2A
]
#send 'pong' frame
...
...
src/ngx_http_push_stream_module_websocket.c
View file @
bbc74d46
...
...
@@ -310,11 +310,16 @@ ngx_http_push_stream_websocket_reading(ngx_http_request_t *r)
}
}
ctx
->
frame
->
step
=
NGX_HTTP_PUSH_STREAM_WEBSOCKET_READ_START_STEP
;
ctx
->
frame
->
last
=
NULL
;
if
(
ctx
->
frame
->
opcode
==
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_OPCODE
)
{
ngx_http_push_stream_send_response_text
(
r
,
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PONG_LAST_FRAME_BYTE
,
sizeof
(
NGX_HTTP_PUSH_STREAM_WEBSOCKET_PONG_LAST_FRAME_BYTE
),
1
);
}
if
(
ctx
->
frame
->
opcode
==
NGX_HTTP_PUSH_STREAM_WEBSOCKET_CLOSE_OPCODE
)
{
ngx_http_push_stream_send_response_finalize
(
r
);
}
else
{
ctx
->
frame
->
step
=
NGX_HTTP_PUSH_STREAM_WEBSOCKET_READ_START_STEP
;
ctx
->
frame
->
last
=
NULL
;
rc
=
ngx_http_push_stream_send_response_text
(
r
,
NGX_HTTP_PUSH_STREAM_WEBSOCKET_CLOSE_LAST_FRAME_BYTE
,
sizeof
(
NGX_HTTP_PUSH_STREAM_WEBSOCKET_CLOSE_LAST_FRAME_BYTE
),
1
);
goto
finalize
;
}
return
;
...
...
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