Commit ba82c94c authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

explicitly assigning default value for push_stream_message_template as ~text~

parent 1dc45c17
* Fixing bug which removed default message template
* Removing support for versions 0.7.x * Removing support for versions 0.7.x
* Fixing messages sent to subscribers to be a truly transfer encoding chunked connection * Fixing messages sent to subscribers to be a truly transfer encoding chunked connection
* Removing hack to keep connection open (Thanks _Maxim Dounin_) * Removing hack to keep connection open (Thanks _Maxim Dounin_)
......
...@@ -180,7 +180,7 @@ h3(#directives). Directives ...@@ -180,7 +180,7 @@ h3(#directives). Directives
|push_stream_broadcast_channel_max_qtd|unset|number|location|push_stream_subscriber| |push_stream_broadcast_channel_max_qtd|unset|number|location|push_stream_subscriber|
|push_stream_max_channel_id_length|unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration| |push_stream_max_channel_id_length|unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|push_stream_broadcast_channel_prefix|unset|any string|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration| |push_stream_broadcast_channel_prefix|unset|any string|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|push_stream_message_template|unset|any string|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration| |push_stream_message_template|~text~|any string|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|push_stream_max_number_of_channels|unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration| |push_stream_max_number_of_channels|unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|push_stream_max_number_of_broadcast_channels|unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration| |push_stream_max_number_of_broadcast_channels|unset|number|http, location|(push_stream_subscriber and push_stream_publisher) or main nginx configuration|
|push_stream_memory_cleanup_timeout|30 seconds|time constant|http|main nginx configuration| |push_stream_memory_cleanup_timeout|30 seconds|time constant|http|main nginx configuration|
...@@ -251,7 +251,7 @@ The text that will be sended to subscribers when they arrive. ...@@ -251,7 +251,7 @@ The text that will be sended to subscribers when they arrive.
h4(#push_stream_message_template). push_stream_message_template [ string ] h4(#push_stream_message_template). push_stream_message_template [ string ]
default: - default: ~text~
context: location context: location
location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration location: (push_stream_subscriber and push_stream_publisher) or main nginx configuration
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
static time_t NGX_HTTP_PUSH_STREAM_DEFAULT_MEMORY_CLEANUP_TIMEOUT = 30; // 30 seconds static time_t NGX_HTTP_PUSH_STREAM_DEFAULT_MEMORY_CLEANUP_TIMEOUT = 30; // 30 seconds
#define NGX_HTTP_PUSH_STREAM_DEFAULT_HEADER_TEMPLATE "" #define NGX_HTTP_PUSH_STREAM_DEFAULT_HEADER_TEMPLATE ""
#define NGX_HTTP_PUSH_STREAM_DEFAULT_MESSAGE_TEMPLATE "" #define NGX_HTTP_PUSH_STREAM_DEFAULT_MESSAGE_TEMPLATE "~text~"
#define NGX_HTTP_PUSH_STREAM_DEFAULT_CONTENT_TYPE "text/plain" #define NGX_HTTP_PUSH_STREAM_DEFAULT_CONTENT_TYPE "text/plain"
......
...@@ -394,9 +394,9 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) ...@@ -394,9 +394,9 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
// ping message interval cannot be set without a message template // message template cannot be blank
if ((conf->ping_message_interval != NGX_CONF_UNSET_MSEC) && (conf->ping_message_interval > 0) && (conf->message_template.len == 0)) { if (conf->message_template.len == 0) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "cannot have ping message if push_stream_message_template is not set or blank."); ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push_stream_message_template cannot be blank.");
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
...@@ -473,9 +473,7 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) ...@@ -473,9 +473,7 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->header_template.len = aux->len; conf->header_template.len = aux->len;
} }
if (conf->message_template.len > 0) { conf->message_template_index = ngx_http_push_stream_find_or_add_template(cf, conf->message_template);
conf->message_template_index = ngx_http_push_stream_find_or_add_template(cf, conf->message_template);
}
// calc buffer cleanup interval // calc buffer cleanup interval
if (conf->buffer_timeout != NGX_CONF_UNSET) { if (conf->buffer_timeout != NGX_CONF_UNSET) {
......
...@@ -586,47 +586,38 @@ ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx ...@@ -586,47 +586,38 @@ ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx
u_char *txt = NULL; u_char *txt = NULL;
ngx_str_t *str = NULL; ngx_str_t *str = NULL;
if (message_template.len > 0) { u_char template[message_template.len + 1];
u_char template[message_template.len + 1]; ngx_memset(template, '\0', message_template.len + 1);
ngx_memset(template, '\0', message_template.len + 1); ngx_memcpy(template, message_template.data, message_template.len);
ngx_memcpy(template, message_template.data, message_template.len);
u_char char_id[NGX_INT_T_LEN];
ngx_memset(char_id, '\0', NGX_INT_T_LEN);
u_char *msg = NGX_HTTP_PUSH_STREAM_PING_MESSAGE_TEXT.data;
u_char *channel_id = NGX_HTTP_PUSH_STREAM_PING_CHANNEL_ID.data;
ngx_int_t message_id = NGX_HTTP_PUSH_STREAM_PING_MESSAGE_ID;
if (channel != NULL) {
channel_id = channel->id.data;
}
if (message != NULL) {
message_id = message->id;
len = ngx_buf_size(message->buf);
msg = ngx_pcalloc(pool, len + 1);
ngx_memset(msg, '\0', len + 1);
ngx_memcpy(msg, message->buf->pos, len);
}
ngx_sprintf(char_id, "%d", message_id);
txt = ngx_http_push_stream_str_replace(template, NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_ID.data, char_id, 0, pool); u_char char_id[NGX_INT_T_LEN];
txt = ngx_http_push_stream_str_replace(txt, NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_CHANNEL.data, channel_id, 0, pool); ngx_memset(char_id, '\0', NGX_INT_T_LEN);
txt = ngx_http_push_stream_str_replace(txt, NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TEXT.data, msg, 0, pool); u_char *msg = NGX_HTTP_PUSH_STREAM_PING_MESSAGE_TEXT.data;
u_char *channel_id = NGX_HTTP_PUSH_STREAM_PING_CHANNEL_ID.data;
ngx_int_t message_id = NGX_HTTP_PUSH_STREAM_PING_MESSAGE_ID;
} else if (message != NULL) { if (channel != NULL) {
ngx_str_t msg = ngx_string(message->buf->pos); channel_id = channel->id.data;
msg.len = ngx_buf_size(message->buf);
txt = ngx_http_push_stream_append_crlf(&msg, pool);
} }
if (txt != NULL) { if (message != NULL) {
len = ngx_strlen(txt); message_id = message->id;
str = ngx_pcalloc(pool, sizeof(ngx_str_t)); len = ngx_buf_size(message->buf);
str->data = txt; msg = ngx_pcalloc(pool, len + 1);
str->len = len; ngx_memset(msg, '\0', len + 1);
ngx_memcpy(msg, message->buf->pos, len);
} }
ngx_sprintf(char_id, "%d", message_id);
txt = ngx_http_push_stream_str_replace(template, NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_ID.data, char_id, 0, pool);
txt = ngx_http_push_stream_str_replace(txt, NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_CHANNEL.data, channel_id, 0, pool);
txt = ngx_http_push_stream_str_replace(txt, NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TEXT.data, msg, 0, pool);
len = ngx_strlen(txt);
str = ngx_pcalloc(pool, sizeof(ngx_str_t));
str->data = txt;
str->len = len;
return str; return str;
} }
......
...@@ -17,19 +17,8 @@ class TestSetuParameters < Test::Unit::TestCase ...@@ -17,19 +17,8 @@ class TestSetuParameters < Test::Unit::TestCase
assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'") assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'")
end end
def test_ping_message_interval_cannot_be_set_without_a_message_template def test_message_template_cannot_be_blank
expected_error_message = "cannot have ping message if push_stream_message_template is not set or blank" expected_error_message = "push_stream_message_template cannot be blank"
@ping_message_interval = "1s"
@message_template = nil
self.create_config_file
stderr_msg = self.start_server
assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'")
end
def test_ping_message_interval_cannot_be_set_if_message_template_is_blank
expected_error_message = "cannot have ping message if push_stream_message_template is not set or blank"
@ping_message_interval = "1s"
@message_template = "" @message_template = ""
self.create_config_file self.create_config_file
......
...@@ -571,6 +571,53 @@ class TestPublisher < Test::Unit::TestCase ...@@ -571,6 +571,53 @@ class TestPublisher < Test::Unit::TestCase
} }
end end
def config_test_default_message_template
@message_template = nil
@header_template = nil
end
def test_default_message_template
headers = {'accept' => 'application/json'}
channel = 'ch_test_default_message_template'
body = 'body'
EventMachine.run {
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 30
sub_1.stream { |chunk|
assert_equal("#{body}\r\n", chunk, "Wrong message")
EventMachine.stop
}
#publish a message
publish_message_inline(channel, headers, body)
}
end
def config_test_ping_message_with_default_message_template
@message_template = nil
@header_template = nil
@ping_message_interval = '1s'
end
def test_ping_message_with_default_message_template
headers = {'accept' => 'application/json'}
channel = 'ch_test_ping_message_with_default_message_template'
body = 'body'
EventMachine.run {
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 30
sub_1.stream { |chunk|
assert_equal("\r\n", chunk, "Wrong message")
EventMachine.stop
}
EM.add_timer(5) do
fail("Test timeout reached")
EventMachine.stop
end
}
end
def test_transfer_encoding_chuncked def test_transfer_encoding_chuncked
headers = {'accept' => 'application/json'} headers = {'accept' => 'application/json'}
channel = 'ch_test_transfer_encoding_chuncked' channel = 'ch_test_transfer_encoding_chuncked'
......
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