Commit 3da6cb0e authored by Wandenberg's avatar Wandenberg

convert etag header on weak etag to work with the latests releases of nginx gzip filter

parent b5db1acb
...@@ -72,7 +72,7 @@ describe "Subscriber Properties" do ...@@ -72,7 +72,7 @@ describe "Subscriber Properties" do
expect(time_diff_sec(start, stop)).to be_in_the_interval(10, 10.5) expect(time_diff_sec(start, stop)).to be_in_the_interval(10, 10.5)
expect(sub).to be_http_status(304).without_body expect(sub).to be_http_status(304).without_body
expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i) expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i)
expect(sub.response_header['ETAG'].to_s).to eql("0") expect(sub.response_header['ETAG'].to_s).to eql("W/0")
EventMachine.stop EventMachine.stop
end end
end end
...@@ -91,7 +91,7 @@ describe "Subscriber Properties" do ...@@ -91,7 +91,7 @@ describe "Subscriber Properties" do
expect(time_diff_sec(start, stop)).to be_in_the_interval(5, 5.5) expect(time_diff_sec(start, stop)).to be_in_the_interval(5, 5.5)
expect(sub).to be_http_status(304).without_body expect(sub).to be_http_status(304).without_body
expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i) expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i)
expect(sub.response_header['ETAG'].to_s).to eql("0") expect(sub.response_header['ETAG'].to_s).to eql("W/0")
EventMachine.stop EventMachine.stop
end end
end end
...@@ -110,7 +110,7 @@ describe "Subscriber Properties" do ...@@ -110,7 +110,7 @@ describe "Subscriber Properties" do
expect(time_diff_sec(start, stop)).to be_in_the_interval(3, 3.5) expect(time_diff_sec(start, stop)).to be_in_the_interval(3, 3.5)
expect(sub).to be_http_status(304).without_body expect(sub).to be_http_status(304).without_body
expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i) expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i)
expect(sub.response_header['ETAG'].to_s).to eql("0") expect(sub.response_header['ETAG'].to_s).to eql("W/0")
EventMachine.stop EventMachine.stop
end end
end end
...@@ -153,7 +153,7 @@ describe "Subscriber Properties" do ...@@ -153,7 +153,7 @@ describe "Subscriber Properties" do
expect(response["tag"]).to eql("0") expect(response["tag"]).to eql("0")
expect(response["time"]).to eql("Thu, 01 Jan 1970 00:00:00 GMT") expect(response["time"]).to eql("Thu, 01 Jan 1970 00:00:00 GMT")
expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i) expect(Time.parse(sub.response_header['LAST_MODIFIED'].to_s).utc.to_i).to be_in_the_interval(Time.now.utc.to_i-1, Time.now.utc.to_i)
expect(sub.response_header['ETAG'].to_s).to eql("0") expect(sub.response_header['ETAG'].to_s).to eql("W/0")
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => headers
sub_1.callback do sub_1.callback do
...@@ -183,7 +183,7 @@ describe "Subscriber Properties" do ...@@ -183,7 +183,7 @@ describe "Subscriber Properties" do
expect(sub_2).to be_http_status(200) expect(sub_2).to be_http_status(200)
response = JSON.parse(sub_2.response) response = JSON.parse(sub_2.response)
expect(response["channel"]).to eql(channel_2) expect(response["channel"]).to eql(channel_2)
expect(sub_2.response_header['ETAG'].to_i).to eql(sub_1.response_header['ETAG'].to_i + 1) expect(sub_2.response_header['ETAG'].sub("W/", "").to_i).to eql(sub_1.response_header['ETAG'].sub("W/", "").to_i + 1)
EventMachine.stop EventMachine.stop
end end
...@@ -357,6 +357,7 @@ describe "Subscriber Properties" do ...@@ -357,6 +357,7 @@ describe "Subscriber Properties" do
sub_1.callback do sub_1.callback do
expect(sub_1).to be_http_status(200) expect(sub_1).to be_http_status(200)
expect(sub_1.response_header["ETAG"]).to match(/W\/\d+/)
expect(sub_1.response_header["CONTENT_ENCODING"]).to eql("gzip") expect(sub_1.response_header["CONTENT_ENCODING"]).to eql("gzip")
actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read
......
...@@ -25,7 +25,7 @@ describe "Subscriber Properties" do ...@@ -25,7 +25,7 @@ describe "Subscriber Properties" do
it "should receive a 304 keeping sent headers" do it "should receive a 304 keeping sent headers" do
channel = 'ch_test_receive_a_304_when_has_no_messages_keeping_headers' channel = 'ch_test_receive_a_304_when_has_no_messages_keeping_headers'
sent_headers = headers.merge({'If-Modified-Since' => Time.now.utc.strftime("%a, %d %b %Y %T %Z"), 'If-None-Match' => '3'}) sent_headers = headers.merge({'If-Modified-Since' => Time.now.utc.strftime("%a, %d %b %Y %T %Z"), 'If-None-Match' => 'W/3'})
nginx_run_server(config) do |conf| nginx_run_server(config) do |conf|
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers
...@@ -55,7 +55,7 @@ describe "Subscriber Properties" do ...@@ -55,7 +55,7 @@ describe "Subscriber Properties" do
sub_1.callback do sub_1.callback do
expect(sub_1).to be_http_status(200) expect(sub_1).to be_http_status(200)
expect(sub_1.response_header['LAST_MODIFIED'].to_s).not_to eql("") expect(sub_1.response_header['LAST_MODIFIED'].to_s).not_to eql("")
expect(sub_1.response_header['ETAG'].to_s).to eql("1") expect(sub_1.response_header['ETAG'].to_s).to eql("W/1")
expect(sub_1.response).to eql("#{body}") expect(sub_1.response).to eql("#{body}")
EventMachine.stop EventMachine.stop
end end
...@@ -148,6 +148,7 @@ describe "Subscriber Properties" do ...@@ -148,6 +148,7 @@ describe "Subscriber Properties" do
sub_1.callback do sub_1.callback do
expect(sub_1).to be_http_status(200) expect(sub_1).to be_http_status(200)
expect(sub_1.response_header["ETAG"]).to match(/W\/\d+/)
expect(sub_1.response_header["CONTENT_ENCODING"]).to eql("gzip") expect(sub_1.response_header["CONTENT_ENCODING"]).to eql("gzip")
actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read
......
...@@ -223,7 +223,7 @@ describe "Receive old messages" do ...@@ -223,7 +223,7 @@ describe "Receive old messages" do
get_content(nginx_address + '/sub/' + channel.to_s, 4, sent_headers) do |response, response_headers| get_content(nginx_address + '/sub/' + channel.to_s, 4, sent_headers) do |response, response_headers|
if ["long-polling", "polling"].include?(conf.subscriber_mode) if ["long-polling", "polling"].include?(conf.subscriber_mode)
expect(response_headers['LAST_MODIFIED'].to_s).not_to eql("") expect(response_headers['LAST_MODIFIED'].to_s).not_to eql("")
expect(response_headers['ETAG'].to_s).to eql("10") expect(response_headers['ETAG'].to_s).to eql("W/10")
end end
expect(response).to eql("msg 6\r\nmsg 7\r\nmsg 8\r\nmsg 9\r\n") expect(response).to eql("msg 6\r\nmsg 7\r\nmsg 8\r\nmsg 9\r\n")
...@@ -243,7 +243,7 @@ describe "Receive old messages" do ...@@ -243,7 +243,7 @@ describe "Receive old messages" do
get_content(nginx_address + '/sub/' + channel.to_s, 1, sent_headers) do |response, response_headers| get_content(nginx_address + '/sub/' + channel.to_s, 1, sent_headers) do |response, response_headers|
if ["long-polling", "polling"].include?(conf.subscriber_mode) if ["long-polling", "polling"].include?(conf.subscriber_mode)
expect(response_headers['LAST_MODIFIED'].to_s).not_to eql("") expect(response_headers['LAST_MODIFIED'].to_s).not_to eql("")
expect(response_headers['ETAG'].to_s).to eql("1") expect(response_headers['ETAG'].to_s).to eql("W/1")
end end
expect(response).to eql("msg 1#{eol}") expect(response).to eql("msg 1#{eol}")
...@@ -267,7 +267,7 @@ describe "Receive old messages" do ...@@ -267,7 +267,7 @@ describe "Receive old messages" do
get_content(nginx_address + '/sub/' + channel.to_s + '?' + params, 4, headers) do |response, response_headers| get_content(nginx_address + '/sub/' + channel.to_s + '?' + params, 4, headers) do |response, response_headers|
if ["long-polling", "polling"].include?(conf.subscriber_mode) if ["long-polling", "polling"].include?(conf.subscriber_mode)
expect(response_headers['LAST_MODIFIED'].to_s).not_to eql("") expect(response_headers['LAST_MODIFIED'].to_s).not_to eql("")
expect(response_headers['ETAG'].to_s).to eql("10") expect(response_headers['ETAG'].to_s).to eql("W/10")
end end
expect(response).to eql("msg 6\r\nmsg 7\r\nmsg 8\r\nmsg 9\r\n") expect(response).to eql("msg 6\r\nmsg 7\r\nmsg 8\r\nmsg 9\r\n")
......
...@@ -1815,9 +1815,9 @@ ngx_http_push_stream_add_polling_headers(ngx_http_request_t *r, time_t last_modi ...@@ -1815,9 +1815,9 @@ ngx_http_push_stream_add_polling_headers(ngx_http_request_t *r, time_t last_modi
} }
if (tag >= 0) { if (tag >= 0) {
ngx_str_t *etag = ngx_http_push_stream_create_str(temp_pool, NGX_INT_T_LEN); ngx_str_t *etag = ngx_http_push_stream_create_str(temp_pool, NGX_INT_T_LEN + 3);
if (etag != NULL) { if (etag != NULL) {
ngx_sprintf(etag->data, "%ui", tag); ngx_sprintf(etag->data, "W/%ui%Z", tag);
etag->len = ngx_strlen(etag->data); etag->len = ngx_strlen(etag->data);
r->headers_out.etag = ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ETAG, etag); r->headers_out.etag = ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ETAG, etag);
} }
...@@ -1846,6 +1846,11 @@ ngx_http_push_stream_get_last_received_message_values(ngx_http_request_t *r, tim ...@@ -1846,6 +1846,11 @@ ngx_http_push_stream_get_last_received_message_values(ngx_http_request_t *r, tim
etag = ngx_http_push_stream_get_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_IF_NONE_MATCH); etag = ngx_http_push_stream_get_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_IF_NONE_MATCH);
} }
if ((etag != NULL) && (etag->len > 2) && (etag->data[0] == 'W') && (etag->data[1] == '/')) {
etag->len -= 2;
etag->data = etag->data + 2;
}
if (cf->last_event_id != NULL) { if (cf->last_event_id != NULL) {
ngx_http_push_stream_complex_value(r, cf->last_event_id, &vv_event_id); ngx_http_push_stream_complex_value(r, cf->last_event_id, &vv_event_id);
if (vv_event_id.len) { if (vv_event_id.len) {
......
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