Hi<b> </b>Maxim<br>Can you please tell the file name I should be looking for correct example of using <span style="color:rgb(0,0,0);font-family:Arial;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);font-size:medium;display:inline!important;float:none">ngx_http_read_client_request_body for content handler module </span>?<br>
<br><br clear="all">regards<div>Vivek Goel</div><br>
<br><br><div class="gmail_quote">On Mon, Mar 19, 2012 at 6:03 PM, vivek goel <span dir="ltr"><<a href="mailto:goelvivek2011@gmail.com">goelvivek2011@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I am writing my own module to generate contents. <br>I am getting random time-outs with it. <br>What can be the issue ?<br><br>Following is the source code for my module <br><br><br>/*<br> * Copyright (C) Igor Sysoev<br> * Copyright (C) Nginx, Inc.<br>
*/<br><br>#include <ngx_config.h><br>#include <ngx_core.h><br>#include <ngx_http.h><br><br>typedef struct {<br> ngx_flag_t done : 1;<br> ngx_flag_t waiting_more_body : 1;<br>} ngx_http_helloworld_ctx_t;<br>
<br><br>static char *ngx_http_helloworld(ngx_conf_t *cf, ngx_command_t *cmd,<br> void *conf);<br>static void ngx_http_form_input_post_read(ngx_http_request_t *r);<br><br>static ngx_command_t ngx_http_helloworld_commands[] = {<br>
<br> { ngx_string("helloworld"),<br> NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_NOARGS,<br> ngx_http_helloworld,<br> 0,<br> 0,<br> NULL},<br><br>
ngx_null_command<br>
};<br><br><br><br><br>//static u_char ngx_helloworld[] = "ABCD";<br><br><br>static ngx_http_module_t ngx_http_helloworld_module_ctx = {<br> NULL, /* preconfiguration */<br> NULL, /* postconfiguration */<br>
<br> NULL, /* create main configuration */<br> NULL, /* init main configuration */<br><br> NULL, /* create server configuration */<br> NULL, /* merge server configuration */<br><br> NULL, /* create location configuration */<br>
NULL /* merge location configuration */<br>};<br><br><br>ngx_module_t ngx_http_helloworld_module = {<br> NGX_MODULE_V1,<br> &ngx_http_helloworld_module_ctx, /* module context */<br> ngx_http_helloworld_commands, /* module directives */<br>
NGX_HTTP_MODULE, /* module type */<br> NULL, /* init master */<br> NULL, /* init module */<br> NULL, /* init process */<br> NULL, /* init thread */<br> NULL, /* exit thread */<br> NULL, /* exit process */<br>
NULL, /* exit master */<br> NGX_MODULE_V1_PADDING<br>};<br><br><br>static ngx_str_t ngx_http_gif_type = ngx_string("text/html");<br><br>static ngx_int_t<br>ngx_http_helloworld_handler(ngx_http_request_t *r) {<br>
ngx_http_complex_value_t cv;<br> ngx_http_helloworld_ctx_t *ctx;<br><br><br><br> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,<br> "http form_input rewrite phase handler");<br>
<br> ctx = ngx_http_get_module_ctx(r, ngx_http_helloworld_module);<br><br> if (ctx != NULL) {<br> if (ctx->done) {<br> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,<br> "http form_input rewrite phase handler done");<br>
<br> return NGX_DECLINED;<br> }<br><br> return NGX_DONE;<br> }<br><br> ctx = ngx_pcalloc(r->pool, sizeof (ngx_http_helloworld_ctx_t));<br> if (ctx == NULL) {<br> return NGX_ERROR;<br>
}<br><br> /* set by ngx_pcalloc:<br> * ctx->done = 0;<br> * ctx->waiting_more_body = 0;<br> */<br><br> ngx_http_set_ctx(r, ctx, ngx_http_helloworld_module);<br><br><br><br><br><br> if (!(r->method & (NGX_HTTP_GET | NGX_HTTP_POST))) {<br>
return NGX_HTTP_NOT_ALLOWED;<br> }<br><br> ngx_memzero(&cv, sizeof (ngx_http_complex_value_t));<br> if (r->method == NGX_HTTP_POST) {<br> ngx_int_t rc = ngx_http_read_client_request_body(r, ngx_http_form_input_post_read);<br>
if (rc) {<br> }<br> }<br><br> /*<br> ngx_str_t b;<br> ngx_str_set(&b,"/b");<br> return ngx_http_internal_redirect(r, &b,NULL);<br> */<br> return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_gif_type, &cv);<br>
}<br><br>static char *<br>ngx_http_helloworld(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {<br> ngx_http_core_loc_conf_t *clcf;<br><br> clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);<br> clcf->handler = ngx_http_helloworld_handler;<br>
<br> return NGX_CONF_OK;<br>}<br><br>static void ngx_http_form_input_post_read(ngx_http_request_t *r) {<br> ngx_http_helloworld_ctx_t *ctx;<br><br> ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,<br>
"http form_input post read request body");<br><br> r->read_event_handler = ngx_http_request_empty_handler;<br><br> ctx = ngx_http_get_module_ctx(r, ngx_http_helloworld_module);<br> if (ctx == NULL) {<br>
return;<br> }<br> ctx->done = 1;<br><br>#if defined(nginx_version) && nginx_version >= 8011<br><br> r->main->count--;<br>#endif<br><br><br><br><br> if (ctx->waiting_more_body) {<br>
ctx->waiting_more_body = 0;<br><br> ngx_http_core_run_phases(r);<br> }<br>}<br><br><br clear="all">regards<span class="HOEnZb"><font color="#888888"><div>Vivek Goel</div><br>
</font></span></blockquote></div><br>