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
7a676397
Commit
7a676397
authored
Apr 14, 2013
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set expires headers to avoid cache
parent
92b9aaff
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
230 additions
and
0 deletions
+230
-0
ngx_http_push_stream_module.h
include/ngx_http_push_stream_module.h
+15
-0
ngx_http_push_stream_module_utils.h
include/ngx_http_push_stream_module_utils.h
+3
-0
channel_statistics_spec.rb
misc/spec/mix/channel_statistics_spec.rb
+15
-0
properties_spec.rb
misc/spec/publisher/properties_spec.rb
+15
-0
long_polling_spec.rb
misc/spec/subscriber/long_polling_spec.rb
+15
-0
polling_spec.rb
misc/spec/subscriber/polling_spec.rb
+15
-0
properties_spec.rb
misc/spec/subscriber/properties_spec.rb
+15
-0
websocket_spec.rb
misc/spec/subscriber/websocket_spec.rb
+15
-0
ngx_http_push_stream_module_publisher.c
src/ngx_http_push_stream_module_publisher.c
+2
-0
ngx_http_push_stream_module_subscriber.c
src/ngx_http_push_stream_module_subscriber.c
+2
-0
ngx_http_push_stream_module_utils.c
src/ngx_http_push_stream_module_utils.c
+116
-0
ngx_http_push_stream_module_websocket.c
src/ngx_http_push_stream_module_websocket.c
+2
-0
No files found.
include/ngx_http_push_stream_module.h
View file @
7a676397
...
...
@@ -349,4 +349,19 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOWED_HEADERS = ngx_string("If-Mo
#define NGX_HTTP_PUSH_STREAM_TIME_FMT_LEN 30 //sizeof("Mon, 28 Sep 1970 06:00:00 GMT")
/**
* borrowed from Nginx core files
*/
typedef
enum
{
NGX_HTTP_PUSH_STREAM_EXPIRES_OFF
,
NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH
,
NGX_HTTP_PUSH_STREAM_EXPIRES_MAX
,
NGX_HTTP_PUSH_STREAM_EXPIRES_ACCESS
,
NGX_HTTP_PUSH_STREAM_EXPIRES_MODIFIED
,
NGX_HTTP_PUSH_STREAM_EXPIRES_DAILY
,
NGX_HTTP_PUSH_STREAM_EXPIRES_UNSET
}
ngx_http_push_stream_expires_t
;
#endif
/* NGX_HTTP_PUSH_STREAM_MODULE_H_ */
include/ngx_http_push_stream_module_utils.h
View file @
7a676397
...
...
@@ -292,4 +292,7 @@ static ngx_str_t * ngx_http_push_stream_get_formatted_hostname(ngx_pool
uint64_t
ngx_http_push_stream_htonll
(
uint64_t
value
);
uint64_t
ngx_http_push_stream_ntohll
(
uint64_t
value
);
static
ngx_int_t
ngx_http_push_stream_set_expires
(
ngx_http_request_t
*
r
,
ngx_http_push_stream_expires_t
expires
,
time_t
expires_time
);
#endif
/* NGX_HTTP_PUSH_STREAM_MODULE_UTILS_H_ */
misc/spec/mix/channel_statistics_spec.rb
View file @
7a676397
...
...
@@ -633,4 +633,19 @@ describe "Channel Statistics" do
end
end
end
it
"should not cache the response"
do
channel
=
'ch_test_not_cache_the_response'
nginx_run_server
(
config
)
do
|
conf
|
EventMachine
.
run
do
pub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/channels-stats?id='
+
channel
.
to_s
).
get
:head
=>
headers
pub_1
.
callback
do
pub_1
.
response_header
[
"EXPIRES"
].
should
eql
(
"Thu, 01 Jan 1970 00:00:01 GMT"
)
pub_1
.
response_header
[
"CACHE_CONTROL"
].
should
eql
(
"no-cache, no-store, must-revalidate"
)
EventMachine
.
stop
end
end
end
end
end
misc/spec/publisher/properties_spec.rb
View file @
7a676397
...
...
@@ -388,6 +388,21 @@ describe "Publisher Properties" do
end
end
end
it
"should not cache the response"
do
channel
=
'ch_test_not_cache_the_response'
nginx_run_server
(
config
)
do
|
conf
|
EventMachine
.
run
do
pub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/pub?id='
+
channel
.
to_s
).
get
:head
=>
headers
pub_1
.
callback
do
pub_1
.
response_header
[
"EXPIRES"
].
should
eql
(
"Thu, 01 Jan 1970 00:00:01 GMT"
)
pub_1
.
response_header
[
"CACHE_CONTROL"
].
should
eql
(
"no-cache, no-store, must-revalidate"
)
EventMachine
.
stop
end
end
end
end
end
context
"when is on normal mode"
do
...
...
misc/spec/subscriber/long_polling_spec.rb
View file @
7a676397
...
...
@@ -407,6 +407,21 @@ describe "Subscriber Properties" do
end
end
end
it
"should not cache the response"
do
channel
=
'ch_test_not_cache_the_response'
nginx_run_server
(
config
.
merge
(
:longpolling_connection_ttl
=>
'1s'
))
do
|
conf
|
EventMachine
.
run
do
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
sub_1
.
callback
do
sub_1
.
response_header
[
"EXPIRES"
].
should
eql
(
"Thu, 01 Jan 1970 00:00:01 GMT"
)
sub_1
.
response_header
[
"CACHE_CONTROL"
].
should
eql
(
"no-cache, no-store, must-revalidate"
)
EventMachine
.
stop
end
end
end
end
end
context
"when using subscriber push mode config"
do
...
...
misc/spec/subscriber/polling_spec.rb
View file @
7a676397
...
...
@@ -340,6 +340,21 @@ describe "Subscriber Properties" do
end
end
it
"should not cache the response"
do
channel
=
'ch_test_not_cache_the_response'
nginx_run_server
(
config
)
do
|
conf
|
EventMachine
.
run
do
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
sub_1
.
callback
do
sub_1
.
response_header
[
"EXPIRES"
].
should
eql
(
"Thu, 01 Jan 1970 00:00:01 GMT"
)
sub_1
.
response_header
[
"CACHE_CONTROL"
].
should
eql
(
"no-cache, no-store, must-revalidate"
)
EventMachine
.
stop
end
end
end
end
end
context
"when using subscriber push mode config"
do
...
...
misc/spec/subscriber/properties_spec.rb
View file @
7a676397
...
...
@@ -907,4 +907,19 @@ describe "Subscriber Properties" do
end
end
end
it
"should not cache the response"
do
channel
=
'ch_test_not_cache_the_response'
nginx_run_server
(
config
.
merge
(
:subscriber_connection_ttl
=>
'1s'
))
do
|
conf
|
EventMachine
.
run
do
sub_1
=
EventMachine
::
HttpRequest
.
new
(
nginx_address
+
'/sub/'
+
channel
.
to_s
).
get
:head
=>
headers
sub_1
.
callback
do
sub_1
.
response_header
[
"EXPIRES"
].
should
eql
(
"Thu, 01 Jan 1970 00:00:01 GMT"
)
sub_1
.
response_header
[
"CACHE_CONTROL"
].
should
eql
(
"no-cache, no-store, must-revalidate"
)
EventMachine
.
stop
end
end
end
end
end
misc/spec/subscriber/websocket_spec.rb
View file @
7a676397
...
...
@@ -394,4 +394,19 @@ describe "Subscriber WebSocket" do
end
end
end
it
"should not cache the response"
do
channel
=
'ch_test_not_cache_the_response'
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
)
headers
.
should
include
(
"Expires: Thu, 01 Jan 1970 00:00:01 GMT
\r\n
"
)
headers
.
should
include
(
"Cache-Control: no-cache, no-store, must-revalidate
\r\n
"
)
end
end
end
src/ngx_http_push_stream_module_publisher.c
View file @
7a676397
...
...
@@ -36,6 +36,7 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
r
->
keepalive
=
cf
->
keepalive
;
ngx_http_push_stream_set_expires
(
r
,
NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH
,
0
);
if
(
cf
->
allowed_origins
.
len
>
0
)
{
ngx_http_push_stream_add_response_header
(
r
,
&
NGX_HTTP_PUSH_STREAM_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
,
&
cf
->
allowed_origins
);
...
...
@@ -216,6 +217,7 @@ ngx_http_push_stream_channels_statistics_handler(ngx_http_request_t *r)
ngx_http_push_stream_loc_conf_t
*
cf
=
ngx_http_get_module_loc_conf
(
r
,
ngx_http_push_stream_module
);
r
->
keepalive
=
cf
->
keepalive
;
ngx_http_push_stream_set_expires
(
r
,
NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH
,
0
);
// only accept GET method
if
(
!
(
r
->
method
&
NGX_HTTP_GET
))
{
...
...
src/ngx_http_push_stream_module_subscriber.c
View file @
7a676397
...
...
@@ -63,6 +63,8 @@ ngx_http_push_stream_subscriber_handler(ngx_http_request_t *r)
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_OK
,
NULL
);
}
ngx_http_push_stream_set_expires
(
r
,
NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH
,
0
);
// only accept GET method
if
(
!
(
r
->
method
&
NGX_HTTP_GET
))
{
ngx_http_push_stream_add_response_header
(
r
,
&
NGX_HTTP_PUSH_STREAM_HEADER_ALLOW
,
&
NGX_HTTP_PUSH_STREAM_ALLOW_GET
);
...
...
src/ngx_http_push_stream_module_utils.c
View file @
7a676397
...
...
@@ -1704,3 +1704,119 @@ ngx_http_push_stream_unescape_uri(ngx_str_t *value)
}
}
}
/**
* borrowed from Nginx core files
*/
static
ngx_int_t
ngx_http_push_stream_set_expires
(
ngx_http_request_t
*
r
,
ngx_http_push_stream_expires_t
expires
,
time_t
expires_time
)
{
size_t
len
;
time_t
now
,
expires_header_time
,
max_age
;
ngx_uint_t
i
;
ngx_table_elt_t
*
expires_header
,
*
cc
,
**
ccp
;
expires_header
=
r
->
headers_out
.
expires
;
if
(
expires_header
==
NULL
)
{
expires_header
=
ngx_list_push
(
&
r
->
headers_out
.
headers
);
if
(
expires_header
==
NULL
)
{
return
NGX_ERROR
;
}
r
->
headers_out
.
expires
=
expires_header
;
expires_header
->
hash
=
1
;
ngx_str_set
(
&
expires_header
->
key
,
"Expires"
);
}
len
=
sizeof
(
"Mon, 28 Sep 1970 06:00:00 GMT"
);
expires_header
->
value
.
len
=
len
-
1
;
ccp
=
r
->
headers_out
.
cache_control
.
elts
;
if
(
ccp
==
NULL
)
{
if
(
ngx_array_init
(
&
r
->
headers_out
.
cache_control
,
r
->
pool
,
1
,
sizeof
(
ngx_table_elt_t
*
))
!=
NGX_OK
)
{
return
NGX_ERROR
;
}
ccp
=
ngx_array_push
(
&
r
->
headers_out
.
cache_control
);
if
(
ccp
==
NULL
)
{
return
NGX_ERROR
;
}
cc
=
ngx_list_push
(
&
r
->
headers_out
.
headers
);
if
(
cc
==
NULL
)
{
return
NGX_ERROR
;
}
cc
->
hash
=
1
;
ngx_str_set
(
&
cc
->
key
,
"Cache-Control"
);
*
ccp
=
cc
;
}
else
{
for
(
i
=
1
;
i
<
r
->
headers_out
.
cache_control
.
nelts
;
i
++
)
{
ccp
[
i
]
->
hash
=
0
;
}
cc
=
ccp
[
0
];
}
if
(
expires
==
NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH
)
{
expires_header
->
value
.
data
=
(
u_char
*
)
"Thu, 01 Jan 1970 00:00:01 GMT"
;
ngx_str_set
(
&
cc
->
value
,
"no-cache, no-store, must-revalidate"
);
return
NGX_OK
;
}
if
(
expires
==
NGX_HTTP_PUSH_STREAM_EXPIRES_MAX
)
{
expires_header
->
value
.
data
=
(
u_char
*
)
"Thu, 31 Dec 2037 23:55:55 GMT"
;
/* 10 years */
ngx_str_set
(
&
cc
->
value
,
"max-age=315360000"
);
return
NGX_OK
;
}
expires_header
->
value
.
data
=
ngx_pnalloc
(
r
->
pool
,
len
);
if
(
expires_header
->
value
.
data
==
NULL
)
{
return
NGX_ERROR
;
}
if
(
expires_time
==
0
&&
expires
!=
NGX_HTTP_PUSH_STREAM_EXPIRES_DAILY
)
{
ngx_memcpy
(
expires_header
->
value
.
data
,
ngx_cached_http_time
.
data
,
ngx_cached_http_time
.
len
+
1
);
ngx_str_set
(
&
cc
->
value
,
"max-age=0"
);
return
NGX_OK
;
}
now
=
ngx_time
();
if
(
expires
==
NGX_HTTP_PUSH_STREAM_EXPIRES_DAILY
)
{
expires_header_time
=
ngx_next_time
(
expires_time
);
max_age
=
expires_header_time
-
now
;
}
else
if
(
expires
==
NGX_HTTP_PUSH_STREAM_EXPIRES_ACCESS
||
r
->
headers_out
.
last_modified_time
==
-
1
)
{
expires_header_time
=
now
+
expires_time
;
max_age
=
expires_time
;
}
else
{
expires_header_time
=
r
->
headers_out
.
last_modified_time
+
expires_time
;
max_age
=
expires_header_time
-
now
;
}
ngx_http_time
(
expires_header
->
value
.
data
,
expires_header_time
);
if
(
expires_time
<
0
||
max_age
<
0
)
{
ngx_str_set
(
&
cc
->
value
,
"no-cache, no-store, must-revalidate"
);
return
NGX_OK
;
}
cc
->
value
.
data
=
ngx_pnalloc
(
r
->
pool
,
sizeof
(
"max-age="
)
+
NGX_TIME_T_LEN
+
1
);
if
(
cc
->
value
.
data
==
NULL
)
{
return
NGX_ERROR
;
}
cc
->
value
.
len
=
ngx_sprintf
(
cc
->
value
.
data
,
"max-age=%T"
,
max_age
)
-
cc
->
value
.
data
;
return
NGX_OK
;
}
src/ngx_http_push_stream_module_websocket.c
View file @
7a676397
...
...
@@ -52,6 +52,8 @@ ngx_http_push_stream_websocket_handler(ngx_http_request_t *r)
return
ngx_http_push_stream_send_only_header_response
(
r
,
NGX_HTTP_NOT_ALLOWED
,
NULL
);
}
ngx_http_push_stream_set_expires
(
r
,
NGX_HTTP_PUSH_STREAM_EXPIRES_EPOCH
,
0
);
upgrade_header
=
ngx_http_push_stream_get_header
(
r
,
&
NGX_HTTP_PUSH_STREAM_HEADER_UPGRADE
);
connection_header
=
ngx_http_push_stream_get_header
(
r
,
&
NGX_HTTP_PUSH_STREAM_HEADER_CONNECTION
);
sec_key_header
=
ngx_http_push_stream_get_header
(
r
,
&
NGX_HTTP_PUSH_STREAM_HEADER_SEC_WEBSOCKET_KEY
);
...
...
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