Commit 92e02b7b authored by Wandenberg Peixoto's avatar Wandenberg Peixoto Committed by Wandenberg

converting channel_id and channels_path from variables into directives

parent 243c9882
h1(#changelog). Changelog
* Changed push_stream_channel_id variable to directive
* Changed push_stream_channels_path variable to directive
* Back to use Nginx chunked filter
h2. Version 0.3.5
......
......@@ -31,7 +31,7 @@ h1(#basic-configuration). Basic Configuration
push_stream_channels_statistics;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location /pub {
......@@ -39,7 +39,7 @@ h1(#basic-configuration). Basic Configuration
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location ~ /sub/(.*) {
......@@ -47,7 +47,7 @@ h1(#basic-configuration). Basic Configuration
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
}
</pre>
......@@ -96,10 +96,6 @@ h1(#examples). Some Examples <a name="examples" href="#">&nbsp;</a>
* "Long Polling":long_polling
* "JSONP":jsonp
h1(#variables). Variables
* "push_stream_channel_id":push_stream_channel_id
* "push_stream_channels_path":push_stream_channels_path
h1(#directives). Directives
......@@ -122,6 +118,8 @@ h1(#directives). Directives
| "push_stream_max_number_of_channels":push_stream_max_number_of_channels | &nbsp;&nbsp;- | &nbsp;&nbsp;x | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- |
| "push_stream_max_number_of_broadcast_channels":push_stream_max_number_of_broadcast_channels | &nbsp;&nbsp;- | &nbsp;&nbsp;x | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- |
| "push_stream_broadcast_channel_prefix":push_stream_broadcast_channel_prefix | &nbsp;&nbsp;- | &nbsp;&nbsp;x | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- |
| "push_stream_channel_id":push_stream_channel_id | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x |
| "push_stream_channels_path":push_stream_channels_path | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x | &nbsp;&nbsp;x | &nbsp;&nbsp;x | &nbsp;&nbsp;- |
| "push_stream_authorized_channels_only":push_stream_authorized_channels_only | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x |
| "push_stream_header_template":push_stream_header_template | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x |
| "push_stream_message_template":push_stream_message_template | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x | &nbsp;&nbsp;- | &nbsp;&nbsp;- | &nbsp;&nbsp;x |
......@@ -211,8 +209,6 @@ h1(#contributors). Contributors
[websocket]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/examples/websocket.textile#websocket
[long_polling]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/examples/long_polling.textile#long_polling
[jsonp]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/examples/long_polling.textile#jsonp
[push_stream_channel_id]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/variables.textile#push_stream_channel_id
[push_stream_channels_path]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/variables.textile#push_stream_channels_path
[tests]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/server_tests.textile
[push_stream_channels_statistics]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/channels_statistics.textile#push_stream_channels_statistics
[push_stream_publisher]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/publishers.textile#push_stream_publisher
......@@ -230,6 +226,8 @@ h1(#contributors). Contributors
[push_stream_max_number_of_channels]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/main.textile#push_stream_max_number_of_channels
[push_stream_max_number_of_broadcast_channels]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/main.textile#push_stream_max_number_of_broadcast_channels
[push_stream_broadcast_channel_prefix]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/main.textile#push_stream_broadcast_channel_prefix
[push_stream_channel_id]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/publishers.textile#push_stream_channel_id
[push_stream_channels_path]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_channels_path
[push_stream_authorized_channels_only]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_authorized_channels_only
[push_stream_header_template]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_header_template
[push_stream_message_template]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_message_template
......
......@@ -9,7 +9,7 @@ h2(#push_stream_channels_statistics). push_stream_channels_statistics <a name="p
*release version:* _0.2.0_
Defines a location as a source of statistics. You can use this location to get statistics about a specific, group or all channels, in a resumed ou summarized way.
To get statistics about all channels in a summarized way you have to make a GET in this location without specify a name in the push_stream_channel_id variable.
To get statistics about all channels in a summarized way you have to make a GET in this location without specify a name in the push_stream_channel_id directive.
To get statistics about all channels in a detailed way you have to specify "ALL" in the push_stream_channel_id.
To get statistics about prefixed channels in a detailed way you have to specify "_prefix_*" in the push_stream_channel_id.
To get statistics about a channel you have to specify the name in the push_stream_channel_id.
......@@ -19,7 +19,7 @@ You can get statistics in the formats plain, xml, yaml and json. The default is
<pre>
location /channels-stats {
push_stream_channels_statistics;
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
# /channels-stats -> get statistics about all channels in a summarized way
......
......@@ -18,7 +18,7 @@ DELETE, remove any existent stored messages, disconnect any subscriber, and dele
# normal publisher location
location /pub {
push_stream_publisher;
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
# GET /pub?id=channel_id -> get statistics about a channel
......@@ -27,7 +27,7 @@ DELETE, remove any existent stored messages, disconnect any subscriber, and dele
# admin publisher location
location /pub_admin {
push_stream_publisher admin;
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
# GET /pub_admin?id=channel_id -> get statistics about a channel
......@@ -35,6 +35,22 @@ DELETE, remove any existent stored messages, disconnect any subscriber, and dele
# DELETE /pub_admin?id=channel_id -> delete the channel
</pre>
h2(#push_stream_channel_id). push_stream_channel_id <a name="push_stream_channel_id" href="#">&nbsp;</a>
*values:* _channel id_
*location:* _push_stream_publisher, push_stream_channels_statistics_
A string to uniquely identify a communication channel. Must be present on location of the push_stream_publisher and push_stream_channels_statistics.
<pre>
push_stream_channel_id $arg_id;
#channel id is now the url query string parameter "id"
#(/pub?id=channel_id_string or /channels-stats?id=channel_id_string)
</pre>
h2(#push_stream_store_messages). push_stream_store_messages <a name="push_stream_store_messages" href="#">&nbsp;</a>
*syntax:* _push_stream_store_messages on | off_
......@@ -45,6 +61,7 @@ h2(#push_stream_store_messages). push_stream_store_messages <a name="push_stream
Whether or not message queuing is enabled.
h2(#push_stream_keepalive). push_stream_keepalive <a name="push_stream_keepalive" href="#">&nbsp;</a>
*syntax:* _push_stream_keepalive on | off_
......
......@@ -18,7 +18,7 @@ The polling and long-polling modes could be set by the request header *X-Nginx-P
location /sub/(.*) {
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
}
curl localhost/sub/ch1 -H 'X-Nginx-PushStream-Mode:polling' #polling request on a streaming location
......@@ -28,7 +28,7 @@ The polling and long-polling modes could be set by the request header *X-Nginx-P
location /sub/(.*) {
push_stream_subscriber polling;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
}
curl localhost/sub/ch1 #polling request
......@@ -38,7 +38,7 @@ The polling and long-polling modes could be set by the request header *X-Nginx-P
location /sub/(.*) {
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
}
curl localhost/sub/ch1 #long-polling request
......@@ -64,11 +64,32 @@ This location only supports GET http method to receive published messages.
location /ws/(.*) {
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
}
</pre>
h2(#push_stream_channels_path). push_stream_channels_path <a name="push_stream_channels_path" href="#">&nbsp;</a>
*values:* _set of channels id and backtrack desired messages_
*location:* _push_stream_subscriber_
A string representing a set of channels id and backtrack desired messages separated by slash, example _/channel1.b3/channel2.b5/channel3.b2_.
The backtrack means the amount of old messages from each of the channels that will be delivered to the subscriber. On the example will be 3 messages from channel1, 5 from channel2 and 2 from channel3.
Backtrack isn't needed, you can only sign channels without get old messages, or you can mix things.
More accepted examples: _/channel1_ , _/channel1/channel2_ , _/channel1.b5/channel2_ , _/channel1/channel2.b6_ , ...
Must be present on location of the push_stream_subscriber.
<pre>
location /sub/(.*) {
push_stream_channels_path $1;
}
#channels path is now part of url
#(/sub/channel_id_string or /sub/channel_id_string.b2/other_channel)
</pre>
h2(#push_stream_authorized_channels_only). push_stream_authorized_channels_only <a name="push_stream_authorized_channels_only" href="#">&nbsp;</a>
*syntax:* _push_stream_authorized_channels_only on | off_
......
......@@ -14,7 +14,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location ~ /ev/(.*) {
......@@ -25,7 +25,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_eventsource_support on;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";
......@@ -82,7 +82,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location /ev {
......@@ -93,7 +93,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_eventsource_support on;
# positional channel path
set $push_stream_channels_path $arg_channels;
push_stream_channels_path $arg_channels;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";
......@@ -128,7 +128,7 @@ If needed you can change this behavior changing the javascript usage, like the e
port: window.location.port,
modes: "eventsource",
channelsByArgument: true,
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path variable
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path directive
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
......
......@@ -14,7 +14,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location ~ /sub/(.*) {
......@@ -22,7 +22,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# header to be sent when receiving new subscriber connection
push_stream_header_template "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
......@@ -86,7 +86,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location /sub {
......@@ -94,7 +94,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $arg_channels;
push_stream_channels_path $arg_channels;
# header to be sent when receiving new subscriber connection
push_stream_header_template "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
......@@ -136,7 +136,7 @@ If needed you can change this behavior changing the javascript usage, like the e
port: window.location.port,
modes: "stream",
channelsByArgument: true,
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path variable
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path directive
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
......
......@@ -14,7 +14,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location ~ /lp/(.*) {
......@@ -22,7 +22,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";
......@@ -80,7 +80,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location /lp {
......@@ -88,7 +88,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $arg_channels;
push_stream_channels_path $arg_channels;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";
......@@ -124,7 +124,7 @@ If needed you can change this behavior changing the javascript usage, like the e
port: window.location.port,
modes: "longpolling",
channelsByArgument: true,
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path variable
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path directive
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
......@@ -148,7 +148,7 @@ If needed you can change this behavior using some additional directives and chan
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location ~ /lp/(.*) {
......@@ -156,7 +156,7 @@ If needed you can change this behavior using some additional directives and chan
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":~tag~,\"time\":\"~time~\"}";
......@@ -227,7 +227,7 @@ _The configuration in the example is the same used on long polling, just forcing
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location ~ /lp/(.*) {
......@@ -235,7 +235,7 @@ _The configuration in the example is the same used on long polling, just forcing
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":~tag~,\"time\":\"~time~\"}";
......
......@@ -14,7 +14,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location ~ /ws/(.*) {
......@@ -22,7 +22,7 @@ Create a html page with the content on **Client** part, access it from browser a
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";
......@@ -81,7 +81,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location /ws {
......@@ -89,7 +89,7 @@ If needed you can change this behavior changing the javascript usage, like the e
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $arg_channels;
push_stream_channels_path $arg_channels;
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";
......@@ -126,7 +126,7 @@ If needed you can change this behavior changing the javascript usage, like the e
port: window.location.port,
modes: "websocket",
channelsByArgument: true,
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path variable
channelsArgument: 'channels' //this is the default value, you have to change it to be the same value used on push_stream_channels_path directive
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
......
h1(#variables). Variables
h2(#push_stream_channel_id). push_stream_channel_id <a name="push_stream_channel_id" href="#">&nbsp;</a>
*values:* _channel id_
*location:* _push_stream_publisher, push_stream_channels_statistics_
A string to uniquely identify a communication channel. Must be present on location of the push_stream_publisher and push_stream_channels_statistics.
<pre>
set $push_stream_channel_id $arg_id;
#channel id is now the url query string parameter "id"
#(/pub?id=channel_id_string or /channels-stats?id=channel_id_string)
</pre>
h2(#push_stream_channels_path). push_stream_channels_path <a name="push_stream_channels_path" href="#">&nbsp;</a>
*values:* _set of channels id and backtrack desired messages_
*location:* _push_stream_subscriber_
A string representing a set of channels id and backtrack desired messages separated by slash, example _/channel1.b3/channel2.b5/channel3.b2_.
The backtrack means the amount of old messages from each of the channels that will be delivered to the subscriber. On the example will be 3 messages from channel1, 5 from channel2 and 2 from channel3.
Backtrack isn't needed, you can only sign channels without get old messages, or you can mix things.
More accepted examples: _/channel1_ , _/channel1/channel2_ , _/channel1.b5/channel2_ , _/channel1/channel2.b6_ , ...
Must be present on location of the push_stream_subscriber.
<pre>
location /sub/(.*) {
set $push_stream_channels_path $1;
}
#channels path is now part of url
#(/sub/channel_id_string or /sub/channel_id_string.b2/other_channel)
</pre>
......@@ -68,8 +68,8 @@ typedef struct {
} ngx_http_push_stream_main_conf_t;
typedef struct {
ngx_int_t index_channel_id;
ngx_int_t index_channels_path;
ngx_http_complex_value_t *channel_id;
ngx_http_complex_value_t *channels_path;
ngx_uint_t authorized_channels_only;
ngx_flag_t store_messages;
ngx_str_t header_template;
......
......@@ -52,10 +52,6 @@ static time_t NGX_HTTP_PUSH_STREAM_DEFAULT_CHANNEL_INACTIVITY_TIME = 30;
#define NGX_HTTP_PUSH_STREAM_DEFAULT_BROADCAST_CHANNEL_PREFIX ""
// variables
static ngx_str_t ngx_http_push_stream_channel_id = ngx_string("push_stream_channel_id");
static ngx_str_t ngx_http_push_stream_channels_path = ngx_string("push_stream_channels_path");
static char * ngx_http_push_stream_channels_statistics(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
// publisher
......
......@@ -70,7 +70,7 @@ http {
push_stream_channels_statistics;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location /pub {
......@@ -78,7 +78,7 @@ http {
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
# store messages in memory
push_stream_store_messages off;
......@@ -97,7 +97,7 @@ http {
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# header to be sent when receiving new subscriber connection
push_stream_header_template "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
......@@ -116,7 +116,7 @@ http {
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# activate event source support for this location
push_stream_eventsource_support on;
......@@ -127,7 +127,7 @@ http {
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
}
location ~ /ws/(.*) {
......@@ -135,7 +135,7 @@ http {
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# store messages in memory
push_stream_store_messages on;
......
......@@ -104,6 +104,7 @@ describe "Setup Parameters" do
location ~ /test/ {
push_stream_publisher;
push_stream_eventsource_support on;
push_stream_channel_id $arg_id;
}
}
}
......@@ -116,6 +117,7 @@ describe "Setup Parameters" do
location ~ /test/ {
push_stream_channels_statistics;
push_stream_eventsource_support on;
push_stream_channel_id $arg_id;
}
}
}
......@@ -128,6 +130,7 @@ describe "Setup Parameters" do
location ~ /test/ {
push_stream_websocket;
push_stream_eventsource_support on;
push_stream_channels_path $arg_channels;
}
}
}
......
......@@ -53,6 +53,9 @@ module NginxConfiguration
:channel_info_on_publish => "on",
:channel_inactivity_time => nil,
:channel_id => '$arg_id',
:channels_path => '$1',
:extra_location => ''
}
end
......@@ -143,7 +146,7 @@ http {
push_stream_channels_statistics;
# query string based channel id
set $push_stream_channel_id $arg_id;
<%= write_directive("push_stream_channel_id", channel_id) %>
<%= write_directive("push_stream_keepalive", keepalive, "keepalive") %>
}
......@@ -153,7 +156,7 @@ http {
push_stream_publisher <%= publisher_mode unless publisher_mode.nil? || publisher_mode == "normal" %>;
# query string based channel id
set $push_stream_channel_id $arg_id;
<%= write_directive("push_stream_channel_id", channel_id) %>
<%= write_directive("push_stream_store_messages", store_messages, "store messages") %>
<%= write_directive("push_stream_keepalive", keepalive, "keepalive") %>
<%= write_directive("push_stream_channel_info_on_publish", channel_info_on_publish, "channel_info_on_publish") %>
......@@ -171,7 +174,7 @@ http {
<%= write_directive("push_stream_eventsource_support", eventsource_support, "activate event source support for this location") %>
# positional channel path
set $push_stream_channels_path $1;
<%= write_directive("push_stream_channels_path", channels_path) %>
<%= write_directive("push_stream_content_type", content_type, "content-type") %>
<%= write_directive("push_stream_keepalive", keepalive, "keepalive") %>
}
......
......@@ -372,6 +372,58 @@ describe "Publisher Properties" do
end
end
it "should accept channel id inside an if block" do
merged_config = config.merge({
:header_template => nil,
:footer_template => nil,
:subscriber_connection_ttl => '1s',
:extra_location => %{
location /pub2 {
push_stream_publisher #{config[:publisher_mode]};
push_stream_channel_id $arg_id;
if ($arg_test) {
push_stream_channel_id test_$arg_id;
}
}
}
})
channel = 'channel_id_inside_if_block'
body = 'published message'
resp_1 = ""
resp_2 = ""
nginx_run_server(merged_config) do |conf|
EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.stream do |chunk|
resp_1 += chunk
end
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + 'test_' + channel.to_s).get :head => headers
sub_2.stream do |chunk|
resp_2 += chunk
end
sub_2.callback do
resp_1.should eql("<script>p(1,'channel_id_inside_if_block','published message');</script>\r\n")
resp_2.should eql("<script>p(1,'test_channel_id_inside_if_block','published message');</script>\r\n")
EventMachine.stop
end
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub2?id=' + channel.to_s).post :head => headers, :body => body
pub_1.callback do
pub_1.should be_http_status(200)
end
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub2?id=' + channel.to_s + '&test=1').post :head => headers, :body => body
pub_2.callback do
pub_2.should be_http_status(200)
end
end
end
end
context "when allow origin directive is set" do
it "should receive acess control allow headers" do
channel = 'test_access_control_allow_headers'
......@@ -714,7 +766,7 @@ describe "Publisher Properties" do
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
push_stream_header_template "<html><body>";
push_stream_footer_template "</body></html>";
push_stream_message_template "|~text~|";
......
......@@ -602,7 +602,6 @@ describe "Subscriber Properties" do
end
end
it "should accept different message templates in each location" do
configuration = config.merge({
:message_template => '{\"text\":\"~text~\"}',
......@@ -613,7 +612,7 @@ describe "Subscriber Properties" do
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# message template
push_stream_message_template "{\"msg\":\"~text~\"}";
}
......@@ -922,4 +921,56 @@ describe "Subscriber Properties" do
end
end
end
it "should accept channels path inside an if block" do
merged_config = config.merge({
:header_template => nil,
:footer_template => nil,
:subscriber_connection_ttl => '1s',
:extra_location => %{
location /sub2 {
push_stream_subscriber;
push_stream_channels_path $arg_id;
if ($arg_test) {
push_stream_channels_path test_$arg_id;
}
}
}
})
channel = 'channels_path_inside_if_block'
body = 'published message'
resp_1 = ""
resp_2 = ""
nginx_run_server(merged_config) do |conf|
EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub2?id=' + channel.to_s).get :head => headers
sub_1.stream do |chunk|
resp_1 += chunk
end
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub2?id=' + channel.to_s + '&test=1').get :head => headers
sub_2.stream do |chunk|
resp_2 += chunk
end
sub_2.callback do
resp_1.should eql("<script>p(1,'channels_path_inside_if_block','published message');</script>\r\n")
resp_2.should eql("<script>p(1,'test_channels_path_inside_if_block','published message');</script>\r\n")
EventMachine.stop
end
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub_1.callback do
pub_1.should be_http_status(200)
end
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + 'test_' + channel.to_s).post :head => headers, :body => body
pub_2.callback do
pub_2.should be_http_status(200)
end
end
end
end
end
......@@ -12,7 +12,7 @@ describe "Subscriber WebSocket" do
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
}
}
}
......@@ -287,7 +287,7 @@ describe "Subscriber WebSocket" do
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $1;
push_stream_channels_path $1;
# allow subscriber to publish
push_stream_websocket_allow_publish on;
......
......@@ -60,19 +60,19 @@ http {
location /channels-stats {
push_stream_channels_statistics;
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
}
location /pub {
push_stream_publisher admin;
set $push_stream_channel_id $arg_id;
push_stream_channel_id $arg_id;
push_stream_store_messages off;
push_stream_keepalive on;
}
location ~ /sub/(.*) {
push_stream_subscriber;
set $push_stream_channels_path $1;
push_stream_channels_path $1;
push_stream_message_template "~text~:~id~:~channel~";
}
}
......
......@@ -35,25 +35,26 @@
static ngx_str_t *
ngx_http_push_stream_get_channel_id(ngx_http_request_t *r, ngx_http_push_stream_loc_conf_t *cf)
{
ngx_http_variable_value_t *vv = ngx_http_get_indexed_variable(r, cf->index_channel_id);
ngx_str_t vv = ngx_null_string;
ngx_str_t *id;
if (vv == NULL || vv->not_found || vv->len == 0) {
ngx_http_push_stream_complex_value(r, cf->channel_id, &vv);
if (vv.len == 0) {
return NGX_HTTP_PUSH_STREAM_UNSET_CHANNEL_ID;
}
// maximum length limiter for channel id
if ((ngx_http_push_stream_module_main_conf->max_channel_id_length != NGX_CONF_UNSET_UINT) && (vv->len > ngx_http_push_stream_module_main_conf->max_channel_id_length)) {
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "push stream module: channel id is larger than allowed %d", vv->len);
if ((ngx_http_push_stream_module_main_conf->max_channel_id_length != NGX_CONF_UNSET_UINT) && (vv.len > ngx_http_push_stream_module_main_conf->max_channel_id_length)) {
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "push stream module: channel id is larger than allowed %d", vv.len);
return NGX_HTTP_PUSH_STREAM_TOO_LARGE_CHANNEL_ID;
}
if ((id = ngx_http_push_stream_create_str(r->pool, vv->len)) == NULL) {
if ((id = ngx_http_push_stream_create_str(r->pool, vv.len)) == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: unable to allocate memory for $push_stream_channel_id string");
return NULL;
}
ngx_memcpy(id->data, vv->data, vv->len);
ngx_memcpy(id->data, vv.data, vv.len);
return id;
}
......
......@@ -58,7 +58,7 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
id = ngx_http_push_stream_get_channel_id(r, cf);
if ((id == NULL) || (id == NGX_HTTP_PUSH_STREAM_UNSET_CHANNEL_ID) || (id == NGX_HTTP_PUSH_STREAM_TOO_LARGE_CHANNEL_ID)) {
if (id == NGX_HTTP_PUSH_STREAM_UNSET_CHANNEL_ID) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: the $push_stream_channel_id variable is required but is not set");
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: the push_stream_channel_id is required but is not set");
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_BAD_REQUEST, &NGX_HTTP_PUSH_STREAM_NO_CHANNEL_ID_MESSAGE);
}
if (id == NGX_HTTP_PUSH_STREAM_TOO_LARGE_CHANNEL_ID) {
......
......@@ -128,6 +128,18 @@ static ngx_command_t ngx_http_push_stream_commands[] = {
NULL },
/* Location directives */
{ ngx_string("push_stream_channel_id"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
ngx_http_set_complex_value_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_push_stream_loc_conf_t, channel_id),
NULL },
{ ngx_string("push_stream_channels_path"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
ngx_http_set_complex_value_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_push_stream_loc_conf_t, channels_path),
NULL },
{ ngx_string("push_stream_store_messages"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
......@@ -536,6 +548,8 @@ ngx_http_push_stream_create_loc_conf(ngx_conf_t *cf)
return NGX_CONF_ERROR;
}
lcf->channel_id = NULL;
lcf->channels_path = NULL;
lcf->authorized_channels_only = NGX_CONF_UNSET_UINT;
lcf->store_messages = NGX_CONF_UNSET_UINT;
lcf->message_template_index = -1;
......@@ -584,6 +598,15 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->channel_info_on_publish, prev->channel_info_on_publish, 1);
ngx_conf_merge_str_value(conf->padding_by_user_agent, prev->padding_by_user_agent, NGX_HTTP_PUSH_STREAM_DEFAULT_PADDING_BY_USER_AGENT);
ngx_conf_merge_str_value(conf->allowed_origins, prev->allowed_origins, NGX_HTTP_PUSH_STREAM_DEFAULT_ALLOWED_ORIGINS);
ngx_conf_merge_uint_value(conf->location_type, prev->location_type, NGX_CONF_UNSET_UINT);
if (conf->channel_id == NULL) {
conf->channel_id = prev->channel_id;
}
if (conf->channels_path == NULL) {
conf->channels_path = prev->channels_path;
}
if (conf->last_received_message_time == NULL) {
conf->last_received_message_time = prev->last_received_message_time;
......@@ -601,6 +624,21 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_OK;
}
if ((conf->location_type == NGX_HTTP_PUSH_STREAM_STATISTICS_MODE) ||
(conf->location_type == NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_NORMAL) ||
(conf->location_type == NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_ADMIN)) {
if (conf->channel_id == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: push_stream_channel_id must be set on statistics and publisher location");
return NGX_CONF_ERROR;
}
} else {
if (conf->channels_path == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: push_stream_channels_path must be set on statistics and publisher location");
return NGX_CONF_ERROR;
}
}
// changing properties for event source support
if (conf->eventsource_support) {
if ((conf->location_type != NGX_HTTP_PUSH_STREAM_SUBSCRIBER_MODE_LONGPOLLING) &&
......@@ -777,10 +815,6 @@ ngx_http_push_stream_channels_statistics(ngx_conf_t *cf, ngx_command_t *cmd, voi
if (rc == NGX_CONF_OK) {
ngx_http_push_stream_loc_conf_t *pslcf = conf;
pslcf->location_type = NGX_HTTP_PUSH_STREAM_STATISTICS_MODE;
pslcf->index_channel_id = ngx_http_get_variable_index(cf, &ngx_http_push_stream_channel_id);
if (pslcf->index_channel_id == NGX_ERROR) {
rc = NGX_CONF_ERROR;
}
}
return rc;
......@@ -808,17 +842,7 @@ ngx_http_push_stream_publisher(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}
char *rc = ngx_http_push_stream_setup_handler(cf, conf, &ngx_http_push_stream_publisher_handler);
if (rc == NGX_CONF_OK) {
ngx_http_push_stream_loc_conf_t *pslcf = conf;
pslcf->index_channel_id = ngx_http_get_variable_index(cf, &ngx_http_push_stream_channel_id);
if (pslcf->index_channel_id == NGX_ERROR) {
rc = NGX_CONF_ERROR;
}
}
return rc;
return ngx_http_push_stream_setup_handler(cf, conf, &ngx_http_push_stream_publisher_handler);
}
......@@ -845,17 +869,7 @@ ngx_http_push_stream_subscriber(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}
char *rc = ngx_http_push_stream_setup_handler(cf, conf, &ngx_http_push_stream_subscriber_handler);
if (rc == NGX_CONF_OK) {
ngx_http_push_stream_loc_conf_t *pslcf = conf;
pslcf->index_channels_path = ngx_http_get_variable_index(cf, &ngx_http_push_stream_channels_path);
if (pslcf->index_channels_path == NGX_ERROR) {
rc = NGX_CONF_ERROR;
}
}
return rc;
return ngx_http_push_stream_setup_handler(cf, conf, &ngx_http_push_stream_subscriber_handler);
}
......@@ -867,10 +881,6 @@ ngx_http_push_stream_websocket(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (rc == NGX_CONF_OK) {
ngx_http_push_stream_loc_conf_t *pslcf = conf;
pslcf->location_type = NGX_HTTP_PUSH_STREAM_WEBSOCKET_MODE;
pslcf->index_channels_path = ngx_http_get_variable_index(cf, &ngx_http_push_stream_channels_path);
if (pslcf->index_channels_path == NGX_ERROR) {
rc = NGX_CONF_ERROR;
}
}
#else
rc = NGX_CONF_ERROR;
......
......@@ -81,7 +81,7 @@ ngx_http_push_stream_subscriber_handler(ngx_http_request_t *r)
//get channels ids and backtracks from path
channels_ids = ngx_http_push_stream_parse_channels_ids_from_path(r, ctx->temp_pool);
if ((channels_ids == NULL) || ngx_queue_empty(&channels_ids->queue)) {
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "push stream module: the $push_stream_channels_path variable is required but is not set");
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "push stream module: the push_stream_channels_path is required but is not set");
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_BAD_REQUEST, &NGX_HTTP_PUSH_STREAM_NO_CHANNEL_ID_MESSAGE);
}
......@@ -334,13 +334,14 @@ ngx_http_push_stream_requested_channel_t *
ngx_http_push_stream_parse_channels_ids_from_path(ngx_http_request_t *r, ngx_pool_t *pool) {
ngx_http_push_stream_main_conf_t *mcf = ngx_http_get_module_main_conf(r, ngx_http_push_stream_module);
ngx_http_push_stream_loc_conf_t *cf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module);
ngx_http_variable_value_t *vv_channels_path = ngx_http_get_indexed_variable(r, cf->index_channels_path);
ngx_str_t vv_channels_path = ngx_null_string;
ngx_http_push_stream_requested_channel_t *channels_ids, *cur;
ngx_str_t aux;
int captures[15];
ngx_int_t n;
if (vv_channels_path == NULL || vv_channels_path->not_found || vv_channels_path->len == 0) {
ngx_http_push_stream_complex_value(r, cf->channels_path, &vv_channels_path);
if (vv_channels_path.len == 0) {
return NULL;
}
......@@ -352,9 +353,9 @@ ngx_http_push_stream_parse_channels_ids_from_path(ngx_http_request_t *r, ngx_poo
ngx_queue_init(&channels_ids->queue);
// doing the parser of given channel path
aux.data = vv_channels_path->data;
aux.data = vv_channels_path.data;
do {
aux.len = vv_channels_path->len - (aux.data - vv_channels_path->data);
aux.len = vv_channels_path.len - (aux.data - vv_channels_path.data);
if ((n = ngx_regex_exec(mcf->backtrack_parser_regex, &aux, captures, 15)) >= 0) {
if ((cur = ngx_pcalloc(pool, sizeof(ngx_http_push_stream_requested_channel_t))) == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: unable to allocate memory for channel_id item");
......@@ -375,7 +376,7 @@ ngx_http_push_stream_parse_channels_ids_from_path(ngx_http_request_t *r, ngx_poo
aux.data = aux.data + captures[1];
}
} while ((n != NGX_REGEX_NO_MATCHED) && (aux.data < (vv_channels_path->data + vv_channels_path->len)));
} while ((n != NGX_REGEX_NO_MATCHED) && (aux.data < (vv_channels_path.data + vv_channels_path.len)));
return channels_ids;
}
......
......@@ -79,7 +79,7 @@ ngx_http_push_stream_websocket_handler(ngx_http_request_t *r)
//get channels ids and backtracks from path
channels_ids = ngx_http_push_stream_parse_channels_ids_from_path(r, ctx->temp_pool);
if ((channels_ids == NULL) || ngx_queue_empty(&channels_ids->queue)) {
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "push stream module: the $push_stream_channels_path variable is required but is not set");
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "push stream module: the push_stream_channels_path is required but is not set");
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_BAD_REQUEST, &NGX_HTTP_PUSH_STREAM_NO_CHANNEL_ID_MESSAGE);
}
......
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