Skip to content

Commit b9ff70c

Browse files
committed
Added post_read hook
1 parent 36e3d4d commit b9ff70c

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

nginx/hooks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ def exit_process():
3232
log.debug('exit_process: %r', mod)
3333
mod.exit_process()
3434
_modules.clear()
35+
36+
37+
def post_read():
38+
log.critical('post read hook!')

nginx/nginx.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from .nginx_core cimport ngx_log_error
1010

1111
from . import hooks
1212

13+
1314
cdef public ngx_int_t nginxpy_init_process(ngx_cycle_t *cycle):
1415
ngx_log_error(NGX_LOG_DEBUG, cycle.log, 0,
1516
b'Starting init_process.')
@@ -29,6 +30,7 @@ cdef public ngx_int_t nginxpy_init_process(ngx_cycle_t *cycle):
2930
b'Finished init_process.')
3031
return NGX_OK
3132

33+
3234
cdef public void nginxpy_exit_process(ngx_cycle_t *cycle):
3335
ngx_log_error(NGX_LOG_DEBUG, cycle.log, 0,
3436
b'Starting exit_process.')
@@ -46,6 +48,11 @@ cdef public void nginxpy_exit_process(ngx_cycle_t *cycle):
4648
ngx_log_error(NGX_LOG_DEBUG, cycle.log, 0,
4749
b'Finished exit_process.')
4850

51+
52+
cdef public void nginxpy_post_read():
53+
hooks.post_read()
54+
55+
4956
include "log.pyx"
5057
include "cycle.pyx"
5158
include "asyncio/loop.pyx"

nginx/ngx_python_module.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
static ngx_int_t ngx_python_init_process(ngx_cycle_t *cycle);
99
static void ngx_python_exit_process(ngx_cycle_t *cycle);
10+
static ngx_int_t ngx_python_postconfiguration(ngx_conf_t *cf);
11+
static ngx_int_t ngx_python_post_read(ngx_http_request_t *r);
1012

1113
static wchar_t *python_exec = NULL;
1214

1315

1416
static ngx_http_module_t ngx_python_module_ctx = {
1517
NULL, /* preconfiguration */
16-
NULL, /* postconfiguration */
18+
ngx_python_postconfiguration, /* postconfiguration */
1719

1820
NULL, /* create main configuration */
1921
NULL, /* init main configuration */
@@ -79,3 +81,25 @@ ngx_python_exit_process(ngx_cycle_t *cycle) {
7981
"Failed to finalize Python!");
8082
}
8183
}
84+
85+
static ngx_int_t
86+
ngx_python_postconfiguration(ngx_conf_t *cf) {
87+
ngx_http_handler_pt *h;
88+
ngx_http_core_main_conf_t *cmcf;
89+
90+
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
91+
92+
h = ngx_array_push(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers);
93+
if (h == NULL) {
94+
return NGX_ERROR;
95+
}
96+
*h = ngx_python_post_read;
97+
98+
return NGX_OK;
99+
}
100+
101+
static ngx_int_t
102+
ngx_python_post_read(ngx_http_request_t *r) {
103+
nginxpy_post_read();
104+
return NGX_OK;
105+
}

0 commit comments

Comments
 (0)