Commit b75a4baa authored by Wandenberg Peixoto's avatar Wandenberg Peixoto Committed by Wandenberg

accepting PUT method to publish messages

parent 92e02b7b
h1(#changelog). Changelog
* Changed push_stream_channel_id variable to directive
* Changed push_stream_channels_path variable to directive
* 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
* Back to use Nginx chunked filter
h2. Version 0.3.5
......
......@@ -321,8 +321,8 @@ static const u_char NGX_HTTP_PUSH_STREAM_WEBSOCKET_PAYLOAD_LEN_64_BYTE = 127;
// other stuff
static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_DELETE_METHODS = ngx_string("GET, POST, DELETE");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_METHODS = ngx_string("GET, POST");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_PUT_DELETE_METHODS = ngx_string("GET, POST, PUT, DELETE");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_PUT_METHODS = ngx_string("GET, POST, PUT");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOW_GET = ngx_string("GET");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOWED_HEADERS = ngx_string("If-Modified-Since,If-None-Match");
......
......@@ -87,8 +87,7 @@ describe "Publisher Properties" do
multi.responses[:callback][:a].should_not be_http_status(405)
multi.responses[:callback][:a].req.method.should eql("GET")
multi.responses[:callback][:b].should be_http_status(405)
multi.responses[:callback][:b].response_header['ALLOW'].should eql(accepted_methods)
multi.responses[:callback][:b].should_not be_http_status(405)
multi.responses[:callback][:b].req.method.should eql("PUT")
multi.responses[:callback][:c].should_not be_http_status(405)
......@@ -467,7 +466,7 @@ describe "Publisher Properties" do
end
let(:accepted_methods) do
"GET, POST"
"GET, POST, PUT"
end
it_should_behave_like "publisher location"
......@@ -482,7 +481,7 @@ describe "Publisher Properties" do
{'accept' => 'text/html'}
end
let(:accepted_methods) { "GET, POST, DELETE" }
let(:accepted_methods) { "GET, POST, PUT, DELETE" }
it_should_behave_like "publisher location"
......
......@@ -27,6 +27,23 @@ describe "Publisher Publishing Messages" do
end
end
it "should publish a message with PUT method" do
body = 'published unique message'
channel = 'ch_test_publish_messages_with_put'
nginx_run_server(config, :timeout => 5) do |conf|
EventMachine.run do
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub.stream do |chunk|
chunk.should eql(body + "\r\n")
EventMachine.stop
end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).put :head => headers, :body => body, :timeout => 30
end
end
end
it "should accept messages with different bytes" do
channel = 'ch_test_publish_messages_with_different_bytes'
......
......@@ -43,14 +43,14 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
}
// only accept GET, POST and DELETE methods if enable publisher administration
if ((cf->location_type == NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_ADMIN) && !(r->method & (NGX_HTTP_GET|NGX_HTTP_POST|NGX_HTTP_DELETE))) {
ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ALLOW, &NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_DELETE_METHODS);
if ((cf->location_type == NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_ADMIN) && !(r->method & (NGX_HTTP_GET|NGX_HTTP_POST|NGX_HTTP_PUT|NGX_HTTP_DELETE))) {
ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ALLOW, &NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_PUT_DELETE_METHODS);
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_ALLOWED, NULL);
}
// only accept GET and POST methods if NOT enable publisher administration
if ((cf->location_type != NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_ADMIN) && !(r->method & (NGX_HTTP_GET|NGX_HTTP_POST))) {
ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ALLOW, &NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_METHODS);
if ((cf->location_type != NGX_HTTP_PUSH_STREAM_PUBLISHER_MODE_ADMIN) && !(r->method & (NGX_HTTP_GET|NGX_HTTP_POST|NGX_HTTP_PUT))) {
ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ALLOW, &NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_PUT_METHODS);
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_ALLOWED, NULL);
}
......@@ -70,7 +70,7 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
// search for a existing channel with this id
channel = ngx_http_push_stream_find_channel(id, r->connection->log);
if (r->method == NGX_HTTP_POST) {
if (r->method & (NGX_HTTP_POST|NGX_HTTP_PUT)) {
return ngx_http_push_stream_publisher_handle_post(cf, r, id);
}
......
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