Ticket #1776: ngx_http_neonginx_test.c

File ngx_http_neonginx_test.c, 2.4 KB (added by Andrew, 7 years ago)

simple module for testing purposes

Line 
1#include <ngx_config.h>
2#include <ngx_core.h>
3#include <ngx_http.h>
4
5static ngx_int_t ngx_http_neonginx_test_init(ngx_conf_t *cf);
6static ngx_int_t ngx_http_neonginx_test_handler(ngx_http_request_t *r);
7
8
9static ngx_http_module_t ngx_http_neonginx_test_module_ctx = {
10 NULL, /* preconfiguration */
11 ngx_http_neonginx_test_init, /* postconfiguration */
12
13 NULL, /* create main configuration */
14 NULL, /* init main configuration */
15
16 NULL, /* create server configuration */
17 NULL, /* merge server configuration */
18
19 NULL, /* create location configuration */
20 NULL /* merge location configuration */
21};
22
23
24ngx_module_t ngx_http_neonginx_test_module = {
25 NGX_MODULE_V1,
26 &ngx_http_neonginx_test_module_ctx, /* module context */
27 NULL, /* module directives */
28 NGX_HTTP_MODULE, /* module type */
29 NULL, /* init master */
30 NULL, /* init module */
31 NULL, /* init process */
32 NULL, /* init thread */
33 NULL, /* exit thread */
34 NULL, /* exit process */
35 NULL, /* exit master */
36 NGX_MODULE_V1_PADDING
37};
38
39
40static ngx_int_t
41ngx_http_neonginx_test_handler(ngx_http_request_t *r)
42{
43 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "NEONGINXTEST");
44 return NGX_DECLINED;
45}
46
47
48static ngx_int_t
49ngx_http_neonginx_test_init(ngx_conf_t *cf)
50{
51 ngx_http_handler_pt *h;
52 ngx_http_core_main_conf_t *cmcf;
53
54 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
55
56 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers); // (ATTUALMENTE USIAMO NGX_HTTP_LOG_PHASE INVECE CHE PREACCESS PERCHE PREACCESS HA UN BUG E NELLA LOCATION / VIENE CHIAMATA DUE VOLTE, ES PER IL CONTATORE DELLE RICHIESTE CONTA DOPPIO, O SE METTI QUALCOSA CHE LOGGA LOGGA DOPPIO), PER FARLA CHIAMARE APPENA LA RICHIESTA ARRIVA USARE NGX_HTTP_PREACCESS_PHASE INVECE CHE NGX_HTTP_LOG_PHASE
57 if (h == NULL) {
58 return NGX_ERROR;
59 }
60
61 *h = ngx_http_neonginx_test_handler;
62
63 return NGX_OK;
64}