<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><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>typedef struct {<br> ngx_flag_t done : 1;<br> ngx_flag_t waiting_more_body : 1;<br>} ngx_http_helloworld_ctx_t;<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>
NGX_HTTP_LOC_CONF_OFFSET,<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> char* response;<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> }<br>
<br> //do some processing here<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_input_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> 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<div>Vivek Goel</div><br>
<br><br><div class="gmail_quote">On Fri, Mar 16, 2012 at 7:56 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 was tried to create hello world module to read post request but I am getting ctx as null value on line no 112<br> ctx = ngx_http_get_module_ctx(r, ngx_http_helloworld_module);<br><br>I am attaching the source code <br>
<br clear="all">regards<span class="HOEnZb"><font color="#888888"><div>Vivek Goel</div></font></span><div class="HOEnZb"><div class="h5"><br>
<br><br><div class="gmail_quote">On Sun, Feb 26, 2012 at 11:15 PM, vivek goel <span dir="ltr"><<a href="mailto:goelvivek2011@gmail.com" target="_blank">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">
For reading get request I can use function ngx_http_form_input_arg but I couldn't find any function by using which I can read post data in nginx ?<br>Is there any function in devel module or nginx api I can use to read post data ?<br>
<br clear="all">regards<span><font color="#888888"><div>Vivek Goel</div><br>
</font></span></blockquote></div><br>
</div></div></blockquote></div><br>