Welcome! Log In Create A New Profile

Advanced

ngx_http_read_client_request_body() and ACCESS_PHASE handler

Srebrenko Šehić
April 22, 2010 10:20AM
Hi list,

I am trying to get a module working that can read a POST payload from
the client, have a look at it, and pass it on (unchanged) to the
upstream.

Below is the a sample code I wrote for testing purposes. The code
works as desired for very small POST payloads and with Firefox only.
It doesn't work (even for small payloads) in any other major browser I
tried. The reason for that is that FF sends the POST payload in the
same TCP packet as the HTTP headers - while other browser apparently
send at least 2 packets.

Return code from call to ngx_http_read_client_request_body() is
NGX_AGAIN for non-FF browsers.

What am I doing wrong here?

/usr/local/sbin/nginx -V
nginx version: nginx/0.8.35
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx
--conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx
--pid-path=/var/run/nginx.pid --lock-path=/var/nginx/tmp/nginx.lock
--http-client-body-temp-path=/var/nginx/tmp/client_body_temp
--http-proxy-temp-path=/var/nginx/tmp/proxy_temp
--http-fastcgi-temp-path=/var/nginx/tmp/fastcgi_temp
--http-log-path=/var/log/nginx/access.log
--error-log-path=/var/log/nginx/error.log --user=_nginx --group=_nginx
--with-http_ssl_module --with-http_stub_status_module --with-debug
--with-ipv6 --with-http_perl_module --with-http_sub_module
--add-module=/home/ssehic/dummy

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>

static ngx_int_t ngx_http_dummy_init(ngx_conf_t *cf);

static ngx_http_module_t ngx_http_dummy_module_ctx = {
NULL, /* preconfiguration */
ngx_http_dummy_init, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
NULL, /* create location configuration */
NULL /* merge location configuration */
};


ngx_module_t ngx_http_dummy_module = {
NGX_MODULE_V1,
&ngx_http_dummy_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};

static ngx_int_t ngx_http_dummy_access_handler(ngx_http_request_t *r);

void
ngx_http_dummy_payload_handler(ngx_http_request_t *r)
{
ngx_http_finalize_request(r, NGX_DONE);
}

static ngx_int_t
ngx_http_dummy_access_handler(ngx_http_request_t *r)
{
if (r->method != NGX_HTTP_POST) {
return NGX_OK;
}

return ngx_http_read_client_request_body(r, ngx_http_dummy_payload_handler);
}

static ngx_int_t
ngx_http_dummy_init(ngx_conf_t *cf)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;

cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);

h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}

*h = ngx_http_dummy_access_handler;

return NGX_OK;
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

ngx_http_read_client_request_body() and ACCESS_PHASE handler

Srebrenko Šehić 7157 April 22, 2010 10:20AM

Re: ngx_http_read_client_request_body() and ACCESS_PHASE handler

Yuriy Taraday 1731 April 22, 2010 12:18PM

Re: ngx_http_read_client_request_body() and ACCESS_PHASE handler

Srebrenko Šehić 1559 April 22, 2010 05:50PM

Re: ngx_http_read_client_request_body() and ACCESS_PHASE handler

agentzh 2028 April 23, 2010 04:56AM

Re: ngx_http_read_client_request_body() and ACCESS_PHASE handler

agentzh 1410 April 23, 2010 04:56AM

Re: ngx_http_read_client_request_body() and ACCESS_PHASE handler

Srebrenko Šehić 1694 April 23, 2010 07:22AM

Re: ngx_http_read_client_request_body() and ACCESS_PHASE handler

agentzh 2060 April 24, 2010 05:06AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 305
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