Commit 216cc09c authored by Wandenberg Peixoto's avatar Wandenberg Peixoto Committed by Wandenberg

fix to support gzip usage

parent 211edf51
h1(#changelog). Changelog h1(#changelog). Changelog
* Fix to support gzip usage
* Added the feature to send a custom 'channel delete message' on the body of the DELETE request * 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 * Changed push_stream_channel_id variable to directive, and make possible set it inside an if block
* Changed push_stream_channels_path variable to directive, and make possible set it inside an if block * Changed push_stream_channels_path variable to directive, and make possible set it inside an if block
......
This diff is collapsed.
...@@ -5,7 +5,9 @@ module NginxConfiguration ...@@ -5,7 +5,9 @@ module NginxConfiguration
:master_process => 'on', :master_process => 'on',
:daemon => 'on', :daemon => 'on',
:content_type => 'text/html; charset=utf-8', :gzip => 'off',
:content_type => 'text/html',
:keepalive => 'off', :keepalive => 'off',
:ping_message_interval => '10s', :ping_message_interval => '10s',
...@@ -83,6 +85,14 @@ http { ...@@ -83,6 +85,14 @@ http {
access_log <%= access_log %>; access_log <%= access_log %>;
gzip <%= gzip %>;
gzip_buffers 16 4k;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;
gzip_comp_level 9;
gzip_http_version 1.0;
tcp_nopush on; tcp_nopush on;
tcp_nodelay on; tcp_nodelay on;
keepalive_timeout 100; keepalive_timeout 100;
......
...@@ -454,6 +454,59 @@ describe "Publisher Properties" do ...@@ -454,6 +454,59 @@ describe "Publisher Properties" do
end end
end end
end end
it "should accept respond get requests with gzip" do
channel = 'test_receive_get_response_with_gzip'
body = 'body'
actual_response = ''
nginx_run_server(config.merge(:gzip => "on"), :timeout => 5) do |conf|
EventMachine.run do
#create channel
publish_message_inline(channel, {}, body)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).get :head => headers.merge({'accept' => 'application/json', 'accept-encoding' => 'gzip, compressed'}), :decoding => false
pub.stream do |chunk|
actual_response << chunk
end
pub.callback do
pub.response_header.status.should eql(200)
pub.response_header.content_length.should_not eql(0)
pub.response_header["CONTENT_ENCODING"].should eql("gzip")
actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read
response = JSON.parse(actual_response)
response["channel"].to_s.should eql(channel)
EventMachine.stop
end
end
end
end
it "should accept respond post requests with gzip" do
channel = 'test_receive_post_response_with_gzip'
body = 'body'
actual_response = ''
nginx_run_server(config.merge(:gzip => "on"), :timeout => 5) do |conf|
EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).post :body => body, :head => headers.merge({'accept' => 'application/json', 'accept-encoding' => 'gzip, compressed'}), :decoding => false
pub.stream do |chunk|
actual_response << chunk
end
pub.callback do
pub.response_header.status.should eql(200)
pub.response_header.content_length.should_not eql(0)
pub.response_header["CONTENT_ENCODING"].should eql("gzip")
actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read
response = JSON.parse(actual_response)
response["channel"].to_s.should eql(channel)
EventMachine.stop
end
end
end
end
end end
context "when is on normal mode" do context "when is on normal mode" do
......
...@@ -41,7 +41,6 @@ end ...@@ -41,7 +41,6 @@ end
def publish_message(channel, headers, body) def publish_message(channel, headers, body)
EventMachine.run do EventMachine.run do
pub = publish_message_inline(channel, headers, body) do pub = publish_message_inline(channel, headers, body) do
pub.should be_http_status(200).with_body
response = JSON.parse(pub.response) response = JSON.parse(pub.response)
response["channel"].to_s.should eql(channel) response["channel"].to_s.should eql(channel)
EventMachine.stop EventMachine.stop
...@@ -51,7 +50,7 @@ end ...@@ -51,7 +50,7 @@ end
def create_channel_by_subscribe(channel, headers, timeout=60, &block) def create_channel_by_subscribe(channel, headers, timeout=60, &block)
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => timeout sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s, :connect_timeout => timeout, :inactivity_timeout => timeout).get :head => headers.merge({"accept-encoding" => ""})
sub_1.stream do |chunk| sub_1.stream do |chunk|
block.call block.call
end end
......
...@@ -422,6 +422,32 @@ describe "Subscriber Properties" do ...@@ -422,6 +422,32 @@ describe "Subscriber Properties" do
end end
end end
end end
it "should accpet return content gzipped" do
channel = 'ch_test_get_content_gzipped'
body = 'body'
actual_response = ''
nginx_run_server(config.merge({:gzip => "on"})) do |conf|
EventMachine.run do
sent_headers = headers.merge({'accept-encoding' => 'gzip, compressed'})
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers, :decoding => false
sub_1.stream do |chunk|
actual_response << chunk
end
sub_1.callback do
sub_1.should be_http_status(200)
sub_1.response_header["CONTENT_ENCODING"].should eql("gzip")
actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read
actual_response.should eql("#{body}\r\n")
EventMachine.stop
end
publish_message_inline(channel, {}, body)
end
end
end
end end
context "when using subscriber push mode config" do context "when using subscriber push mode config" do
......
...@@ -339,6 +339,32 @@ describe "Subscriber Properties" do ...@@ -339,6 +339,32 @@ describe "Subscriber Properties" do
end end
end end
it "should accpet return content gzipped" do
channel = 'ch_test_get_content_gzipped'
body = 'body'
actual_response = ''
nginx_run_server(config.merge({:gzip => "on"})) do |conf|
EventMachine.run do
publish_message_inline(channel, {}, body)
sent_headers = headers.merge({'accept-encoding' => 'gzip, compressed'})
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers, :decoding => false
sub_1.stream do |chunk|
actual_response << chunk
end
sub_1.callback do
sub_1.should be_http_status(200)
sub_1.response_header["CONTENT_ENCODING"].should eql("gzip")
actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read
actual_response.should eql("#{body}\r\n")
EventMachine.stop
end
end
end
end
end end
it "should not cache the response" do it "should not cache the response" do
......
...@@ -973,4 +973,30 @@ describe "Subscriber Properties" do ...@@ -973,4 +973,30 @@ describe "Subscriber Properties" do
end end
end end
end end
it "should accpet return content gzipped" do
channel = 'ch_test_get_content_gzipped'
body = 'body'
actual_response = ''
nginx_run_server(config.merge({:gzip => "on", :subscriber_connection_ttl => '1s', :content_type => "text/html"})) do |conf|
EventMachine.run do
sent_headers = headers.merge({'accept-encoding' => 'gzip, compressed'})
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers, :decoding => false
sub_1.stream do |chunk|
actual_response << chunk
end
sub_1.callback do
sub_1.should be_http_status(200)
sub_1.response_header["CONTENT_ENCODING"].should eql("gzip")
actual_response = Zlib::GzipReader.new(StringIO.new(actual_response)).read
actual_response.should eql("HEADER\r\nTEMPLATE\r\n1234\r\n\r\n<script>p(1,'ch_test_get_content_gzipped','body');</script>\r\n</body></html>\r\n")
EventMachine.stop
end
publish_message_inline(channel, {}, body)
end
end
end
end end
...@@ -265,6 +265,7 @@ ngx_http_push_stream_send_response_all_channels_info_detailed(ngx_http_request_t ...@@ -265,6 +265,7 @@ ngx_http_push_stream_send_response_all_channels_info_detailed(ngx_http_request_t
r->headers_out.content_type.len = subtype->content_type->len; r->headers_out.content_type.len = subtype->content_type->len;
r->headers_out.content_type.data = subtype->content_type->data; r->headers_out.content_type.data = subtype->content_type->data;
r->headers_out.content_type_len = subtype->content_type->len;
r->headers_out.content_length_n = content_len; r->headers_out.content_length_n = content_len;
r->headers_out.status = NGX_HTTP_OK; r->headers_out.status = NGX_HTTP_OK;
......
...@@ -489,6 +489,7 @@ ngx_http_push_stream_subscriber_prepare_request_to_keep_connected(ngx_http_reque ...@@ -489,6 +489,7 @@ ngx_http_push_stream_subscriber_prepare_request_to_keep_connected(ngx_http_reque
r->write_event_handler = ngx_http_request_empty_handler; r->write_event_handler = ngx_http_request_empty_handler;
r->headers_out.content_type = cf->content_type; r->headers_out.content_type = cf->content_type;
r->headers_out.content_type_len = cf->content_type.len;
r->headers_out.status = NGX_HTTP_OK; r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = -1; r->headers_out.content_length_n = -1;
......
...@@ -535,6 +535,7 @@ ngx_http_push_stream_send_response(ngx_http_request_t *r, ngx_str_t *text, const ...@@ -535,6 +535,7 @@ ngx_http_push_stream_send_response(ngx_http_request_t *r, ngx_str_t *text, const
r->headers_out.content_type.len = content_type->len; r->headers_out.content_type.len = content_type->len;
r->headers_out.content_type.data = content_type->data; r->headers_out.content_type.data = content_type->data;
r->headers_out.content_type_len = content_type->len;
r->headers_out.content_length_n = text->len; r->headers_out.content_length_n = text->len;
r->headers_out.status = status_code; r->headers_out.status = status_code;
...@@ -1436,6 +1437,7 @@ ngx_http_push_stream_add_polling_headers(ngx_http_request_t *r, time_t last_modi ...@@ -1436,6 +1437,7 @@ ngx_http_push_stream_add_polling_headers(ngx_http_request_t *r, time_t last_modi
ngx_str_t content_type = (ctx->callback != NULL) ? NGX_HTTP_PUSH_STREAM_CALLBACK_CONTENT_TYPE : cf->content_type; ngx_str_t content_type = (ctx->callback != NULL) ? NGX_HTTP_PUSH_STREAM_CALLBACK_CONTENT_TYPE : cf->content_type;
r->headers_out.content_type = content_type; r->headers_out.content_type = content_type;
r->headers_out.content_type_len = content_type.len;
if (last_modified_time > 0) { if (last_modified_time > 0) {
r->headers_out.last_modified_time = last_modified_time; r->headers_out.last_modified_time = last_modified_time;
......
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