Commit e8a6de63 authored by Wandenberg's avatar Wandenberg

change end of line for eventsource from CRLF to LF

parent 9b9dee58
......@@ -207,13 +207,13 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TAG = ngx_string("~ta
static const ngx_str_t NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TIME = ngx_string("~time~");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_COMMENT_PREFIX = ngx_string(": ");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_DEFAULT_HEADER_TEMPLATE = ngx_string(": " CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_COMMENT_TEMPLATE = ngx_string(": ~text~" CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_DEFAULT_HEADER_TEMPLATE = ngx_string(": \n");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_COMMENT_TEMPLATE = ngx_string(": ~text~\n");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_MESSAGE_PREFIX = ngx_string("data: ");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_ID_TEMPLATE = ngx_string("id: ~event-id~" CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_EVENT_TEMPLATE = ngx_string("event: ~event-type~" CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_ID_TEMPLATE = ngx_string("id: ~event-id~\n");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_EVENT_TEMPLATE = ngx_string("event: ~event-type~\n");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_CONTENT_TYPE = ngx_string("text/event-stream; charset=utf-8");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_PING_MESSAGE_CHUNK = ngx_string(": -1" CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_EVENTSOURCE_PING_MESSAGE_CHUNK = ngx_string(": -1\n");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_CALLBACK_INIT_CHUNK = ngx_string("([");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_CALLBACK_MID_CHUNK = ngx_string(",");
......
......@@ -16,6 +16,7 @@ group :test do
gem 'thin', '~> 1.5.1'
gem 'net-http-persistent', '~> 2.9', :require => 'net/http/persistent'
gem 'websocket-eventmachine-client'
gem 'em-eventsource'
gem 'byebug', '~> 1.3.1'
end
......
......@@ -3,7 +3,7 @@ GEM
specs:
Platform (0.4.0)
RedCloth (4.2.9)
addressable (2.3.6)
addressable (2.3.7)
byebug (1.3.1)
columnize (~> 0.3.6)
debugger-linecache (~> 1.2.0)
......@@ -14,6 +14,9 @@ GEM
daemons (1.1.9)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
em-eventsource (0.2.0)
em-http-request (>= 1.0.0)
eventmachine (>= 1.0.0.beta3)
em-http-request (1.0.3)
addressable (>= 2.2.3)
cookiejar
......@@ -22,7 +25,7 @@ GEM
http_parser.rb (>= 0.5.3)
em-socksify (0.3.0)
eventmachine (>= 1.0.0.beta.4)
eventmachine (1.0.3)
eventmachine (1.0.7)
execjs (2.0.2)
ffi (1.9.6)
filewatcher (0.3.4)
......@@ -94,6 +97,7 @@ PLATFORMS
DEPENDENCIES
RedCloth (~> 4.2.9)
byebug (~> 1.3.1)
em-eventsource
em-http-request (~> 1.0.3)
filewatcher
github-markup (~> 0.7.5)
......
This diff is collapsed.
......@@ -198,9 +198,9 @@ describe "Subscriber Padding by user agent" do
describe "for EventSource mode" do
let(:config) { default_config.merge(:subscriber_mode => "eventsource") }
let(:padding_pattern) { /(:::)+\r\n$/ }
let(:header_delta) { 4 }
let(:body_delta) { 10 }
let(:padding_pattern) { /(:::)+\n$/ }
let(:header_delta) { 3 }
let(:body_delta) { 8 }
it_should_behave_like "apply padding"
end
......
......@@ -12,6 +12,8 @@ describe "Receive old messages" do
}
end
let(:eol) { "\r\n" }
shared_examples_for "can receive old messages" do
it "should receive old messages in a multi channel subscriber using backtrack" do
channel_1 = 'ch_test_retreive_old_messages_in_multichannel_subscribe_1'
......@@ -34,7 +36,7 @@ describe "Receive old messages" do
response_headers['ETAG'].to_s.should_not eql("")
end
lines = response.split("\r\n")
lines = response.split(eol)
lines[0].should eql('HEADER')
line = JSON.parse(lines[1])
line['channel'].should eql(channel_2.to_s)
......@@ -93,7 +95,7 @@ describe "Receive old messages" do
response_headers['ETAG'].to_s.should_not eql("")
end
lines = response.split("\r\n")
lines = response.split(eol)
lines[0].should eql('HEADER')
line = JSON.parse(lines[1])
......@@ -148,7 +150,7 @@ describe "Receive old messages" do
response_headers['ETAG'].to_s.should_not eql("")
end
lines = response.split("\r\n")
lines = response.split(eol)
lines[0].should eql('HEADER')
line = JSON.parse(lines[1])
......@@ -244,7 +246,7 @@ describe "Receive old messages" do
response_headers['ETAG'].to_s.should eql("1")
end
response.should eql("msg 1\r\n")
response.should eql("msg 1#{eol}")
end
end
end
......@@ -304,11 +306,11 @@ describe "Receive old messages" do
sub_1 = EventMachine::HttpRequest.new(url).get :head => request_headers
sub_1.stream do |chunk|
response += chunk
lines = response.split("\r\n").map {|line| line.gsub(/^: /, "").gsub(/^data: /, "").gsub(/^id: .*/, "") }.delete_if{|line| line.empty?}.compact
lines = response.split(eol).map {|line| line.gsub(/^: /, "").gsub(/^data: /, "").gsub(/^id: .*/, "") }.delete_if{|line| line.empty?}.compact
if lines.length >= number_expected_lines
EventMachine.stop
block.call("#{lines.join("\r\n")}\r\n", sub_1.response_header) unless block.nil?
block.call("#{lines.join(eol)}#{eol}", sub_1.response_header) unless block.nil?
end
end
end
......@@ -334,6 +336,7 @@ describe "Receive old messages" do
context "in event source mode" do
let(:subscriber_mode) { "eventsource" }
let(:eol) { "\n" }
it_should_behave_like "can receive old messages"
end
......
......@@ -407,8 +407,8 @@ ngx_http_push_stream_postconfig(ngx_conf_t *cf)
}
ngx_memset(aux->data, ':', padding_max_len);
padding_max_len -= 2;
ngx_memcpy(aux->data + padding_max_len, CRLF, 2);
padding_max_len -= 1;
ngx_memcpy(aux->data + padding_max_len, "\n", 1);
ngx_int_t i, len = ngx_http_push_stream_padding_max_len;
for (i = steps; i >= 0; i--) {
......@@ -651,14 +651,14 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
// formatting message template
if (ngx_strncmp(conf->message_template.data, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_MESSAGE_PREFIX.data, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_MESSAGE_PREFIX.len) != 0) {
ngx_str_t *aux = (conf->message_template.len > 0) ? &conf->message_template : (ngx_str_t *) &NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TEXT;
ngx_str_t *template = ngx_http_push_stream_create_str(cf->pool, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_MESSAGE_PREFIX.len + aux->len + ngx_strlen(CRLF));
ngx_str_t *template = ngx_http_push_stream_create_str(cf->pool, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_MESSAGE_PREFIX.len + aux->len + 1);
if (template == NULL) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "push stream module: unable to allocate memory to append message prefix to message template");
return NGX_CONF_ERROR;
}
u_char *last = ngx_copy(template->data, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_MESSAGE_PREFIX.data, NGX_HTTP_PUSH_STREAM_EVENTSOURCE_MESSAGE_PREFIX.len);
last = ngx_copy(last, aux->data, aux->len);
ngx_memcpy(last, CRLF, 2);
ngx_memcpy(last, "\n", 1);
conf->message_template.data = template->data;
conf->message_template.len = template->len;
......
......@@ -323,8 +323,8 @@ ngx_http_push_stream_convert_char_to_msg_on_shared(ngx_http_push_stream_main_con
}
ngx_str_t *tmp = ngx_http_push_stream_join_with_crlf(lines, temp_pool);
if ((aux = ngx_http_push_stream_create_str(temp_pool, tmp->len + 2)) != NULL) {
ngx_sprintf(aux->data, "%V" CRLF, tmp);
if ((aux = ngx_http_push_stream_create_str(temp_pool, tmp->len + 1)) != NULL) {
ngx_sprintf(aux->data, "%V\n", tmp);
}
} else {
aux = ngx_http_push_stream_format_message(channel, msg, &msg->raw, cur->template, temp_pool);
......
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