Hi:
I have a simple module. When I attach a handler to the preaccess phase it ends up being called twice. Any idea why and how i can fix it (code below)?
// Output:
$> curl http://localhost:8090^C
...
$> tail -f error.log |grep AAA
2012/08/09 18:35:45 [debug] 3977#0: *5 AAAAAA: xx handler 9
2012/08/09 18:35:45 [debug] 3977#0: *5 AAAAAA: xx handler 10
// Code
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
static char *ngx_http_play(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t ngx_http_play_init(ngx_conf_t *cf);
static ngx_int_t ngx_http_play_fn(ngx_http_request_t *r);
static ngx_command_t ngx_http_play_commands[] = {
{ ngx_string("play"),
NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
ngx_http_play,
0,
0,
NULL },
ngx_null_command
};
static ngx_http_module_t ngx_http_play_module_ctx = {
NULL, /* preconfiguration */
ngx_http_play_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_play_module = {
NGX_MODULE_V1,
&ngx_http_play_module_ctx, /* module context */
ngx_http_play_commands, /* 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 int i=0;
static ngx_int_t ngx_http_play_fn(ngx_http_request_t *r)
{
i++;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "AAAAAA: xx handler %d", i);
return NGX_OK;
}
static char *ngx_http_play(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, "AAAAAA: conf setup ", i);
return NGX_CONF_OK;
}
static ngx_int_t ngx_http_play_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_PREACCESS_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
*h = ngx_http_play_fn;
return NGX_OK;
}