Commit 67935a78 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

forcing content type as application/javascript on jsonp requests

parent 0a7610f2
......@@ -212,6 +212,7 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_LAST_CHUNK = ngx_string("0" CRLF CR
static const ngx_str_t NGX_HTTP_PUSH_STREAM_CALLBACK_INIT_CHUNK = ngx_string("2" CRLF "([" CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_CALLBACK_MID_CHUNK = ngx_string("1" CRLF "," CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_CALLBACK_END_CHUNK = ngx_string("5" CRLF "]);" CRLF CRLF);
static const ngx_str_t NGX_HTTP_PUSH_STREAM_CALLBACK_CONTENT_TYPE = ngx_string("application/javascript");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_PADDING_BY_USER_AGENT_PATTERN = ngx_string("([^:]+),(\\d+),(\\d+)");
......
......@@ -27,6 +27,6 @@
#define NGX_HTTP_PUSH_STREAM_MODULE_VERSION_H_
static const ngx_str_t NGX_HTTP_PUSH_STREAM_TAG = ngx_string("0.3.4");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_COMMIT = ngx_string("79eb641fa567a24cd87603256cd7d03a19e45aeb");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_COMMIT = ngx_string("0a7610f2b25dadad803cecf740d542e2ac781762");
#endif /* NGX_HTTP_PUSH_STREAM_MODULE_VERSION_H_ */
......@@ -257,7 +257,6 @@ ngx_http_push_stream_subscriber_polling_handler(ngx_http_request_t *r, ngx_http_
}
// polling with messages or long polling without messages to send
r->headers_out.content_type = cf->content_type;
r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = -1;
......
......@@ -1427,6 +1427,12 @@ ngx_http_push_stream_apply_template_to_each_line(ngx_str_t *text, const ngx_str_
static void
ngx_http_push_stream_add_polling_headers(ngx_http_request_t *r, time_t last_modified_time, ngx_int_t tag, ngx_pool_t *temp_pool)
{
ngx_http_push_stream_loc_conf_t *cf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module);
ngx_http_push_stream_subscriber_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_push_stream_module);
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;
if (last_modified_time > 0) {
r->headers_out.last_modified_time = last_modified_time;
}
......
......@@ -575,7 +575,7 @@ class TestSubscriberLongPolling < Test::Unit::TestCase
end
def test_return_message_using_function_name_specified_in_callback_parameter
headers = {'accept' => 'application/json'}
headers = {'accept' => 'application/javascript'}
channel = 'ch_test_return_message_using_function_name_specified_in_callback_parameter'
body = 'body'
response = ""
......@@ -596,7 +596,7 @@ class TestSubscriberLongPolling < Test::Unit::TestCase
end
def test_return_old_messages_using_function_name_specified_in_callback_parameter_grouping_in_one_answer
headers = {'accept' => 'application/json'}
headers = {'accept' => 'application/javascript'}
channel = 'ch_test_return_old_messages_using_function_name_specified_in_callback_parameter_grouping_in_one_answer'
body = 'body'
response = ""
......@@ -617,4 +617,29 @@ class TestSubscriberLongPolling < Test::Unit::TestCase
}
end
def config_test_force_content_type_to_be_application_javascript_when_using_function_name_specified_in_callback_parameter
@content_type = "anything/value"
end
def test_force_content_type_to_be_application_javascript_when_using_function_name_specified_in_callback_parameter
headers = {'accept' => 'otherknown/value'}
channel = 'test_force_content_type_to_be_application_javascript_when_using_function_name_specified_in_callback_parameter'
body = 'body'
response = ""
callback_function_name = "callback_function"
EventMachine.run {
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => headers, :timeout => 30
sub_1.callback {
assert_equal('application/javascript', sub_1.response_header['CONTENT_TYPE'], "Didn't receive the right content type")
EventMachine.stop
}
publish_message_inline(channel, {'accept' => 'text/html'}, body)
add_test_timeout
}
end
end
......@@ -596,7 +596,7 @@ class TestSubscriberPolling < Test::Unit::TestCase
end
def test_return_message_using_function_name_specified_in_callback_parameter_when_polling
headers = {'accept' => 'application/json'}
headers = {'accept' => 'application/javascript'}
channel = 'ch_test_return_message_using_function_name_specified_in_callback_parameter_when_polling'
body = 'body'
response = ""
......@@ -615,4 +615,28 @@ class TestSubscriberPolling < Test::Unit::TestCase
}
end
def config_test_force_content_type_to_be_application_javascript_when_using_function_name_specified_in_callback_parameter_when_polling
@content_type = "anything/value"
end
def test_force_content_type_to_be_application_javascript_when_using_function_name_specified_in_callback_parameter_when_polling
headers = {'accept' => 'otherknown/value'}
channel = 'test_force_content_type_to_be_application_javascript_when_using_function_name_specified_in_callback_parameter_when_polling'
body = 'body'
response = ""
callback_function_name = "callback_function"
EventMachine.run {
publish_message_inline(channel, {'accept' => 'text/html'}, body)
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => headers, :timeout => 30
sub_1.callback {
assert_equal('application/javascript', sub_1.response_header['CONTENT_TYPE'], "Didn't receive the right content type")
EventMachine.stop
}
add_test_timeout
}
end
end
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