Pyry Hakulinen
August 11, 2011 07:40AM
> Thank you for your report.  Please try the attached patch.

Thank you, the patch appears to be working fine, but because it
discards the request body, it isn't going to work for our use case.

Our use case is, to POST data to nginx and let nginx asynchronously
proxy it to somewhere else for processing, while freeing the client
that did the POSTing to do other things.

I think the request body should be transferred to post_action
location, and the location can then decide if it needs it or not.
Attached is a patch against 1.0.5 that reads the body if post_action
is used, but I'm not really sure if it's correct. My nginx-fu is still
a bit lacking.

Thanks,
Pyry
diff -r -u nginx-1.0.5.orig/src//http/modules/ngx_http_empty_gif_module.c nginx-1.0.5.ihazfix/src/http/modules/ngx_http_empty_gif_module.c
--- nginx-1.0.5.orig/src//http/modules/ngx_http_empty_gif_module.c 2010-06-18 18:17:07.000000000 +0300
+++ nginx-1.0.5.ihazfix/src/http/modules/ngx_http_empty_gif_module.c 2011-08-11 09:02:57.282004002 +0300
@@ -111,19 +111,12 @@
static ngx_int_t
ngx_http_empty_gif_handler(ngx_http_request_t *r)
{
- ngx_int_t rc;
ngx_http_complex_value_t cv;

if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
return NGX_HTTP_NOT_ALLOWED;
}

- rc = ngx_http_discard_request_body(r);
-
- if (rc != NGX_OK) {
- return rc;
- }
-
ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));

cv.value.len = sizeof(ngx_empty_gif);
diff -r -u nginx-1.0.5.orig/src//http/ngx_http_core_module.c nginx-1.0.5.ihazfix/src/http/ngx_http_core_module.c
--- nginx-1.0.5.orig/src//http/ngx_http_core_module.c 2011-04-19 15:29:16.000000000 +0300
+++ nginx-1.0.5.ihazfix/src/http/ngx_http_core_module.c 2011-08-11 14:05:59.308273425 +0300
@@ -1760,6 +1760,16 @@
ngx_buf_t *b;
ngx_chain_t out;

+ ngx_http_core_loc_conf_t *clcf;
+
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ if (clcf->post_action.data == NULL) {
+ if (ngx_http_discard_request_body(r) != NGX_OK) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+ }
+
r->headers_out.status = status;

if (status == NGX_HTTP_NO_CONTENT) {
diff -r -u nginx-1.0.5.orig/src//http/ngx_http_request.c nginx-1.0.5.ihazfix/src/http/ngx_http_request.c
--- nginx-1.0.5.orig/src//http/ngx_http_request.c 2011-04-04 15:26:53.000000000 +0300
+++ nginx-1.0.5.ihazfix/src/http/ngx_http_request.c 2011-08-11 14:09:50.728612844 +0300
@@ -48,6 +48,7 @@
static void ngx_http_keepalive_handler(ngx_event_t *ev);
static void ngx_http_set_lingering_close(ngx_http_request_t *r);
static void ngx_http_lingering_close_handler(ngx_event_t *ev);
+static void ngx_http_post_action_read_callback(ngx_http_request_t *r);
static ngx_int_t ngx_http_post_action(ngx_http_request_t *r);
static void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t error);
static void ngx_http_free_request(ngx_http_request_t *r, ngx_int_t error);
@@ -2863,20 +2864,15 @@
return ngx_http_output_filter(r, &out);
}

-
-static ngx_int_t
-ngx_http_post_action(ngx_http_request_t *r)
+static void
+ngx_http_post_action_read_callback(ngx_http_request_t *r)
{
ngx_http_core_loc_conf_t *clcf;

clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

- if (clcf->post_action.data == NULL) {
- return NGX_DECLINED;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "post action: \"%V\"", &clcf->post_action);
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "post action read callback");

r->main->count--;

@@ -2893,9 +2889,25 @@
ngx_http_named_location(r, &clcf->post_action);
}

- return NGX_OK;
+ return;
}

+static ngx_int_t
+ngx_http_post_action(ngx_http_request_t *r)
+{
+ ngx_http_core_loc_conf_t *clcf;
+
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ if (clcf->post_action.data == NULL) {
+ return NGX_DECLINED;
+ }
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "post action: \"%V\"", &clcf->post_action);
+
+ return ngx_http_read_client_request_body(r, ngx_http_post_action_read_callback);
+}

static void
ngx_http_close_request(ngx_http_request_t *r, ngx_int_t rc)
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Problem with post_action when used with return 202; and POST request

Pyry Hakulinen August 10, 2011 07:24AM

Re: Problem with post_action when used with return 202; and POST request

Maxim Dounin August 10, 2011 07:12PM

Re: Problem with post_action when used with return 202; and POST request

Pyry Hakulinen August 11, 2011 07:40AM

Re: Problem with post_action when used with return 202; and POST request

Maxim Dounin August 12, 2011 03:48AM

Re: Problem with post_action when used with return 202; and POST request

Pyry Hakulinen August 13, 2011 04:08PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 162
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready