Commit ec18573c authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

refactor of publisher to put post handler in a different function to be reusable

parent 7777234d
...@@ -206,7 +206,7 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_HEADER_ALLOW = ngx_string("Allow"); ...@@ -206,7 +206,7 @@ static const ngx_str_t NGX_HTTP_PUSH_STREAM_HEADER_ALLOW = ngx_string("Allow");
static const ngx_str_t NGX_HTTP_PUSH_STREAM_HEADER_EXPLAIN = ngx_string("X-Nginx-PushStream-Explain"); static const ngx_str_t NGX_HTTP_PUSH_STREAM_HEADER_EXPLAIN = ngx_string("X-Nginx-PushStream-Explain");
// other stuff // other stuff
static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOWED_METHODS = ngx_string("GET, POST"); 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 = ngx_string("GET"); static const ngx_str_t NGX_HTTP_PUSH_STREAM_ALLOW_GET = ngx_string("GET");
#define NGX_HTTP_PUSH_STREAM_CHECK_AND_FINALIZE_REQUEST_ON_ERROR(val, fail, r, errormessage) \ #define NGX_HTTP_PUSH_STREAM_CHECK_AND_FINALIZE_REQUEST_ON_ERROR(val, fail, r, errormessage) \
......
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
#include <ngx_http_push_stream_module_publisher.h> #include <ngx_http_push_stream_module_publisher.h>
static ngx_int_t ngx_http_push_stream_publisher_handle_post(ngx_http_push_stream_loc_conf_t *cf, ngx_http_request_t *r, ngx_str_t *id);
static ngx_int_t static ngx_int_t
ngx_http_push_stream_publisher_handler(ngx_http_request_t *r) ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
{ {
ngx_int_t rc;
ngx_str_t *id = NULL; ngx_str_t *id = NULL;
ngx_http_push_stream_channel_t *channel = NULL; ngx_http_push_stream_channel_t *channel = NULL;
ngx_http_push_stream_loc_conf_t *cf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module); ngx_http_push_stream_loc_conf_t *cf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module);
...@@ -38,7 +39,7 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r) ...@@ -38,7 +39,7 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
// only accept GET and POST methods // only accept GET and POST methods
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_POST))) { if (!(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_ALLOWED_METHODS); ngx_http_push_stream_add_response_header(r, &NGX_HTTP_PUSH_STREAM_HEADER_ALLOW, &NGX_HTTP_PUSH_STREAM_ALLOW_GET_POST_METHODS);
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_ALLOWED, NULL); return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_ALLOWED, NULL);
} }
...@@ -59,6 +60,23 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r) ...@@ -59,6 +60,23 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
channel = ngx_http_push_stream_find_channel(id, r->connection->log); channel = ngx_http_push_stream_find_channel(id, r->connection->log);
if (r->method == NGX_HTTP_POST) { if (r->method == NGX_HTTP_POST) {
return ngx_http_push_stream_publisher_handle_post(cf, r, id);
}
// GET only make sense with a previous existing channel
if (channel == NULL) {
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_FOUND, NULL);
}
return ngx_http_push_stream_send_response_channel_info(r, channel);
}
static ngx_int_t
ngx_http_push_stream_publisher_handle_post(ngx_http_push_stream_loc_conf_t *cf, ngx_http_request_t *r, ngx_str_t *id)
{
ngx_int_t rc;
ngx_http_push_stream_channel_t *channel = NULL;
// check if channel id isn't equals to ALL // check if channel id isn't equals to ALL
if (ngx_memn2cmp(id->data, NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID.data, id->len, NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID.len) == 0) { if (ngx_memn2cmp(id->data, NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID.data, id->len, NGX_HTTP_PUSH_STREAM_ALL_CHANNELS_INFO_ID.len) == 0) {
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_FORBIDDEN, &NGX_HTTP_PUSH_STREAM_NO_CHANNEL_ID_NOT_AUTHORIZED_MESSAGE); return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_FORBIDDEN, &NGX_HTTP_PUSH_STREAM_NO_CHANNEL_ID_NOT_AUTHORIZED_MESSAGE);
...@@ -92,14 +110,6 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r) ...@@ -92,14 +110,6 @@ ngx_http_push_stream_publisher_handler(ngx_http_request_t *r)
} }
return NGX_DONE; return NGX_DONE;
}
// GET only make sense with a previous existing channel
if (channel == NULL) {
return ngx_http_push_stream_send_only_header_response(r, NGX_HTTP_NOT_FOUND, NULL);
}
return ngx_http_push_stream_send_response_channel_info(r, channel);
} }
static void static void
......
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