Commit ff1afae7 authored by Wandenberg's avatar Wandenberg

change push_stream_eventsource_support directive to be a subtype of...

change push_stream_eventsource_support directive to be a subtype of push_stream_subscriber directive
parent 216cc09c
h1(#changelog). Changelog
* Changed push_stream_eventsource_support directive to be a subtype of push_stream_subscriber directive
* Fix to support gzip usage
* Added the feature to send a custom 'channel delete message' on the body of the DELETE request
* Changed push_stream_channel_id variable to directive, and make possible set it inside an if block
......
......@@ -126,7 +126,6 @@ h1(#directives). Directives
| "push_stream_footer_template":push_stream_footer_template |   - |   - |   x |   - |   - |   x |
| "push_stream_content_type":push_stream_content_type |   - |   - |   x |   - |   - |   - |
| "push_stream_broadcast_channel_max_qtd":push_stream_broadcast_channel_max_qtd |   - |   - |   x |   - |   - |   x |
| "push_stream_eventsource_support":push_stream_eventsource_support |   - |   - |   x |   - |   - |   - |
| "push_stream_ping_message_interval":push_stream_ping_message_interval |   - |   - |   x |   - |   - |   x |
| "push_stream_subscriber_connection_ttl":push_stream_subscriber_connection_ttl |   - |   - |   x |   - |   - |   x |
| "push_stream_longpolling_connection_ttl":push_stream_longpolling_connection_ttl |   - |   - |   x |   - |   - |   - |
......@@ -234,7 +233,6 @@ h1(#contributors). Contributors
[push_stream_footer_template]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_footer_template
[push_stream_content_type]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_content_type
[push_stream_broadcast_channel_max_qtd]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_broadcast_channel_max_qtd
[push_stream_eventsource_support]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_eventsource_support
[push_stream_ping_message_interval]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_ping_message_interval
[push_stream_subscriber_connection_ttl]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_subscriber_connection_ttl
[push_stream_longpolling_connection_ttl]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_longpolling_connection_ttl
......
......@@ -2,7 +2,7 @@ h1(#subscribers_configuration). Subscribers Configuration
h2(#push_stream_subscriber). push_stream_subscriber <a name="push_stream_subscriber" href="#">&nbsp;</a>
*syntax:* _push_stream_subscriber [streaming | polling | long-polling]_
*syntax:* _push_stream_subscriber [streaming | polling | long-polling | eventsource]_
*default:* _streaming_
......@@ -12,6 +12,7 @@ Defines a location as a subscriber. This location represents a subscriber's inte
This location only supports GET http method to receive published messages.
And has three possible values to set push mode: streaming, polling, long-polling. The default values is streaming.
The polling and long-polling modes could be set by the request header *X-Nginx-PushStream-Mode* overriding push_stream_subscriber directive value.
The eventsource mode enable "Event Source":eventsource_ref support for subscribers. Using headers Event-ID and Event-Type on publish is possible to set values to _id:_ and _event:_ attributes on message sent to subscribers.
<pre>
# streaming subscriber location
......@@ -43,6 +44,15 @@ The polling and long-polling modes could be set by the request header *X-Nginx-P
curl localhost/sub/ch1 #long-polling request
curl localhost/sub/ch1 -H 'X-Nginx-PushStream-Mode:polling' #polling request on a logn-polling location
# eventsource subscriber location
location /sub/(.*) {
push_stream_subscriber eventsource;
# positional channel path
push_stream_channels_path $1;
}
curl localhost/sub/ch1 #eventsource request
</pre>
......@@ -160,19 +170,6 @@ The maximum number of broadcast channels that a subscriber may sign on the reque
This directive works in conjunction with push_stream_authorized_channels_only to preserve the server from a kind of attack where a subscriber sign one normal channel and many nonexistent broadcast channels.
h2(#push_stream_eventsource_support). push_stream_eventsource_support <a name="push_stream_eventsource_support" href="#">&nbsp;</a>
*syntax:* _push_stream_eventsource_support on | off_
*default:* _off_
*context:* _location (push_stream_subscriber)_
*release version:* _0.3.0_
Enable "Event Source":eventsource_ref support for subscribers. Using headers Event-ID and Event-Type on publish is possible to set values to _id:_ and _event:_ attributes on message sent to subscribers.
h2(#push_stream_ping_message_interval). push_stream_ping_message_interval <a name="push_stream_ping_message_interval" href="#">&nbsp;</a>
*syntax:* _push_stream_ping_message_interval time_
......
......@@ -18,11 +18,8 @@ Create a html page with the content on **Client** part, access it from browser a
}
location ~ /ev/(.*) {
# activate subscriber mode for this location
push_stream_subscriber;
# activate event source support for this location
push_stream_eventsource_support on;
# activate event source mode for this location
push_stream_subscriber eventsource;
# positional channel path
push_stream_channels_path $1;
......@@ -86,11 +83,8 @@ If needed you can change this behavior changing the javascript usage, like the e
}
location /ev {
# activate subscriber mode for this location
push_stream_subscriber;
# activate event source support for this location
push_stream_eventsource_support on;
# activate event source mode for this location
push_stream_subscriber eventsource;
# positional channel path
push_stream_channels_path $arg_channels;
......
......@@ -79,7 +79,6 @@ typedef struct {
ngx_str_t content_type;
ngx_uint_t broadcast_channel_max_qtd;
ngx_uint_t keepalive;
ngx_flag_t eventsource_support;
ngx_uint_t location_type;
ngx_msec_t ping_message_interval;
ngx_msec_t subscriber_connection_ttl;
......@@ -290,14 +289,17 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_MODE_ADMIN = ngx_string("admin")
static const ngx_str_t NGX_HTTP_PUSH_STREAM_MODE_STREAMING = ngx_string("streaming");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_MODE_POLLING = ngx_string("polling");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_MODE_LONGPOLLING = ngx_string("long-polling");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_MODE_EVENTSOURCE = ngx_string("eventsource");
#define NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_STREAMING 0
#define NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_POLLING 1
#define NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_LONGPOLLING 2
#define NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_NORMAL 3
#define NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_ADMIN 4
#define NGX_HTTP_PUSH_STREAM_STATISTICS_MODE 5
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_MODE 6
#define NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE 3
#define NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_NORMAL 4
#define NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_ADMIN 5
#define NGX_HTTP_PUSH_STREAM_STATISTICS_MODE 6
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_MODE 7
#define NGX_HTTP_PUSH_STREAM_WEBSOCKET_VERSION_8 8
......
......@@ -112,14 +112,11 @@ http {
}
location ~ /ev/(.*) {
# activate subscriber mode for this location
push_stream_subscriber;
# activate event source mode for this location
push_stream_subscriber eventsource;
# positional channel path
push_stream_channels_path $1;
# activate event source support for this location
push_stream_eventsource_support on;
}
location ~ /lp/(.*) {
......
......@@ -78,7 +78,7 @@ describe "Setup Parameters" do
end
it "should not accept an invalid push mode" do
nginx_test_configuration({:subscriber_mode => "unknown"}).should include("invalid push_stream_subscriber mode value: unknown, accepted values (streaming, polling, long-polling)")
nginx_test_configuration({:subscriber_mode => "unknown"}).should include("invalid push_stream_subscriber mode value: unknown, accepted values (streaming, polling, long-polling, eventsource)")
end
it "should accept the known push modes" do
......@@ -86,6 +86,7 @@ describe "Setup Parameters" do
nginx_test_configuration({:subscriber_mode => "streaming"}).should_not include("invalid push_stream_subscriber mode value")
nginx_test_configuration({:subscriber_mode => "polling"}).should_not include("invalid push_stream_subscriber mode value")
nginx_test_configuration({:subscriber_mode => "long-polling"}).should_not include("invalid push_stream_subscriber mode value")
nginx_test_configuration({:subscriber_mode => "eventsource"}).should_not include("invalid push_stream_subscriber mode value")
end
it "should not accept an invalid publisher mode" do
......@@ -98,45 +99,6 @@ describe "Setup Parameters" do
nginx_test_configuration({:publisher_mode => "admin"}).should_not include("invalid push_stream_publisher mode value")
end
it "should not accept enable event source on publisher location" do
config = {
:extra_location => %q{
location ~ /test/ {
push_stream_publisher;
push_stream_eventsource_support on;
push_stream_channel_id $arg_id;
}
}
}
nginx_test_configuration(config).should include("event source support is only available on subscriber location")
end
it "should not accept enable event source on statistics location" do
config = {
:extra_location => %q{
location ~ /test/ {
push_stream_channels_statistics;
push_stream_eventsource_support on;
push_stream_channel_id $arg_id;
}
}
}
nginx_test_configuration(config).should include("event source support is only available on subscriber location")
end
it "should not accept enable event source on websocket location" do
config = {
:extra_location => %q{
location ~ /test/ {
push_stream_websocket;
push_stream_eventsource_support on;
push_stream_channels_path $arg_channels;
}
}
}
nginx_test_configuration(config).should include("event source support is only available on subscriber location")
end
it "should not accept an invalid pattern for padding by user agent" do
nginx_test_configuration({:padding_by_user_agent => "user_agent,as,df"}).should include("padding pattern not match the value user_agent,as,df")
nginx_test_configuration({:padding_by_user_agent => "user_agent;10;0"}).should include("padding pattern not match the value user_agent;10;0")
......
......@@ -47,8 +47,6 @@ module NginxConfiguration
:authorized_channels_only => 'off',
:allowed_origins => nil,
:eventsource_support => 'off',
:client_max_body_size => '32k',
:client_body_buffer_size => '32k',
......@@ -181,8 +179,6 @@ http {
# activate subscriber mode for this location
push_stream_subscriber <%= subscriber_mode unless subscriber_mode.nil? || subscriber_mode == "streaming" %>;
<%= write_directive("push_stream_eventsource_support", eventsource_support, "activate event source support for this location") %>
# positional channel path
<%= write_directive("push_stream_channels_path", channels_path) %>
<%= write_directive("push_stream_content_type", content_type, "content-type") %>
......
......@@ -3,7 +3,7 @@ require 'spec_helper'
describe "Subscriber Event Source" do
let(:config) do
{
:eventsource_support => 'on',
:subscriber_mode => 'eventsource',
:header_template => nil,
:message_template => nil,
:footer_template => nil,
......
......@@ -194,12 +194,6 @@ static ngx_command_t ngx_http_push_stream_commands[] = {
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_push_stream_loc_conf_t, keepalive),
NULL },
{ ngx_string("push_stream_eventsource_support"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_push_stream_loc_conf_t, eventsource_support),
NULL },
{ ngx_string("push_stream_ping_message_interval"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
......@@ -560,7 +554,6 @@ ngx_http_push_stream_create_loc_conf(ngx_conf_t *cf)
lcf->broadcast_channel_max_qtd = NGX_CONF_UNSET_UINT;
lcf->keepalive = NGX_CONF_UNSET_UINT;
lcf->location_type = NGX_CONF_UNSET_UINT;
lcf->eventsource_support = NGX_CONF_UNSET_UINT;
lcf->ping_message_interval = NGX_CONF_UNSET_MSEC;
lcf->subscriber_connection_ttl = NGX_CONF_UNSET_MSEC;
lcf->longpolling_connection_ttl = NGX_CONF_UNSET_MSEC;
......@@ -590,7 +583,6 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_str_value(conf->content_type, prev->content_type, NGX_HTTP_PUSH_STREAM_DEFAULT_CONTENT_TYPE);
ngx_conf_merge_uint_value(conf->broadcast_channel_max_qtd, prev->broadcast_channel_max_qtd, ngx_http_push_stream_module_main_conf->max_number_of_broadcast_channels);
ngx_conf_merge_uint_value(conf->keepalive, prev->keepalive, 0);
ngx_conf_merge_value(conf->eventsource_support, prev->eventsource_support, 0);
ngx_conf_merge_msec_value(conf->ping_message_interval, prev->ping_message_interval, NGX_CONF_UNSET_MSEC);
ngx_conf_merge_msec_value(conf->subscriber_connection_ttl, prev->subscriber_connection_ttl, NGX_CONF_UNSET_MSEC);
ngx_conf_merge_msec_value(conf->longpolling_connection_ttl, prev->longpolling_connection_ttl, conf->subscriber_connection_ttl);
......@@ -640,14 +632,7 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
}
// changing properties for event source support
if (conf->eventsource_support) {
if ((conf->location_type != NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_LONGPOLLING) &&
(conf->location_type != NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_POLLING) &&
(conf->location_type != NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_STREAMING)) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: event source support is only available on subscriber location");
return NGX_CONF_ERROR;
}
if (conf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE) {
conf->content_type.data = NGX_HTTP_PUSH_STREAM_EVENTSOURCE_CONTENT_TYPE.data;
conf->content_type.len = NGX_HTTP_PUSH_STREAM_EVENTSOURCE_CONTENT_TYPE.len;
......@@ -772,8 +757,9 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
if ((conf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_LONGPOLLING) ||
(conf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_POLLING) ||
(conf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_STREAMING) ||
(conf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE) ||
(conf->location_type == NGX_HTTP_PUSH_STREAM_WEBSOCKET_MODE)) {
conf->message_template_index = ngx_http_push_stream_find_or_add_template(cf, conf->message_template, conf->eventsource_support, (conf->location_type == NGX_HTTP_PUSH_STREAM_WEBSOCKET_MODE));
conf->message_template_index = ngx_http_push_stream_find_or_add_template(cf, conf->message_template, (conf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE), (conf->location_type == NGX_HTTP_PUSH_STREAM_WEBSOCKET_MODE));
if (conf->padding_by_user_agent.len > 0) {
if ((conf->paddings = ngx_http_push_stream_parse_paddings(cf, &conf->padding_by_user_agent)) == NULL) {
......@@ -863,8 +849,10 @@ ngx_http_push_stream_subscriber(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*field = NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_POLLING;
} else if ((value.len == NGX_HTTP_PUSH_STREAM_MODE_LONGPOLLING.len) && (ngx_strncasecmp(value.data, NGX_HTTP_PUSH_STREAM_MODE_LONGPOLLING.data, NGX_HTTP_PUSH_STREAM_MODE_LONGPOLLING.len) == 0)) {
*field = NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_LONGPOLLING;
} else if ((value.len == NGX_HTTP_PUSH_STREAM_MODE_EVENTSOURCE.len) && (ngx_strncasecmp(value.data, NGX_HTTP_PUSH_STREAM_MODE_EVENTSOURCE.data, NGX_HTTP_PUSH_STREAM_MODE_EVENTSOURCE.len) == 0)) {
*field = NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE;
} else {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "invalid push_stream_subscriber mode value: %V, accepted values (%s, %s, %s)", &value, NGX_HTTP_PUSH_STREAM_MODE_STREAMING.data, NGX_HTTP_PUSH_STREAM_MODE_POLLING.data, NGX_HTTP_PUSH_STREAM_MODE_LONGPOLLING.data);
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "invalid push_stream_subscriber mode value: %V, accepted values (%s, %s, %s, %s)", &value, NGX_HTTP_PUSH_STREAM_MODE_STREAMING.data, NGX_HTTP_PUSH_STREAM_MODE_POLLING.data, NGX_HTTP_PUSH_STREAM_MODE_LONGPOLLING.data, NGX_HTTP_PUSH_STREAM_MODE_EVENTSOURCE.data);
return NGX_CONF_ERROR;
}
}
......
......@@ -437,7 +437,7 @@ ngx_http_push_stream_send_response_message(ngx_http_request_t *r, ngx_http_push_
ngx_flag_t use_jsonp = (ctx != NULL) && (ctx->callback != NULL);
ngx_int_t rc = NGX_OK;
if (pslcf->eventsource_support) {
if (pslcf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE) {
if (msg->event_id_message != NULL) {
rc = ngx_http_push_stream_send_response_text(r, msg->event_id_message->data, msg->event_id_message->len, 0);
}
......@@ -941,7 +941,7 @@ ngx_http_push_stream_ping_timer_wake_handler(ngx_event_t *ev)
ngx_http_push_stream_loc_conf_t *pslcf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module);
ngx_int_t rc;
if (pslcf->eventsource_support) {
if (pslcf->location_type == NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_EVENTSOURCE) {
rc = ngx_http_push_stream_send_response_text(r, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_PING_MESSAGE_CHUNK.data, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_PING_MESSAGE_CHUNK.len, 0);
} else if (pslcf->location_type == NGX_HTTP_PUSH_STREAM_WEBSOCKET_MODE) {
rc = ngx_http_push_stream_send_response_text(r, NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_LAST_FRAME_BYTE, sizeof(NGX_HTTP_PUSH_STREAM_WEBSOCKET_PING_LAST_FRAME_BYTE), 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment