Commit a03b3f5e authored by Wandenberg's avatar Wandenberg

added support for OPTIONS method on publisher location

parent 0a819f72
h1(#changelog). Changelog
* Added support for OPTIONS method on publisher location
* Unified longPollingTimeout and timeout configurations on javascript client
* Renamed some javascript client configurations
** jsonDataKey -> jsonTextKey
......
......@@ -72,6 +72,13 @@ describe "Publisher Properties" do
it "should check accepted methods" do
nginx_run_server(config) do |conf|
# testing OPTIONS method, EventMachine::HttpRequest does not have support to it
socket = open_socket(nginx_host, nginx_port)
socket.print("OPTIONS /pub?id=ch_test_accepted_methods HTTP/1.0\r\n\r\n")
headers, body = read_response_on_socket(socket)
headers.should match_the_pattern(/HTTP\/1\.1 200 OK/)
headers.should match_the_pattern(/Content-Length: 0/)
EventMachine.run do
multi = EventMachine::MultiRequest.new
......@@ -348,12 +355,31 @@ describe "Publisher Properties" do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).get :head => headers
pub.callback do
pub.response_header['ACCESS_CONTROL_ALLOW_ORIGIN'].should be_nil
pub.response_header['ACCESS_CONTROL_ALLOW_METHODS'].should be_nil
EventMachine.stop
end
end
end
end
context "when allow origin directive is set" do
it "should receive acess control allow headers" do
channel = 'test_access_control_allow_headers'
nginx_run_server(config.merge(:allowed_origins => "custom.domain.com")) do |conf|
EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).get :head => headers
pub.callback do
pub.response_header['ACCESS_CONTROL_ALLOW_ORIGIN'].should eql("custom.domain.com")
pub.response_header['ACCESS_CONTROL_ALLOW_METHODS'].should eql("GET, POST, PUT, DELETE")
EventMachine.stop
end
end
end
end
end
it "should not receive channel info after publish a message when disabled" do
body = 'published message'
......
......@@ -40,6 +40,11 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
if (cf->allowed_origins.len > 0) {
ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, &cf->allowed_origins);
ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ACCESS_CONTROL_ALLOW_METHODS, &NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_PUT_DELETE_METHODS);
}
if (r->method & NGX_HTTP_OPTIONS) {
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_OK, NULL);
}
// only accept GET, POST, PUT and DELETE methods if enable publisher administration
......
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