Skip to content

Commit 7740e11

Browse files
defanatoragentzh
authored andcommitted
feature: nginx 1.11.11+ can now build with this module.
Note: nginx 1.11.11+ are still not an officially supported target yet. More work needed. Closes #64 See also: http://hg.nginx.org/nginx/rev/e662cbf1b932 Signed-off-by: Yichun Zhang (agentzh) <[email protected]>
1 parent cca1150 commit 7740e11

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

src/ngx_http_echo_module.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ ngx_http_echo_echo_exec(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
632632
static void *
633633
ngx_http_echo_create_main_conf(ngx_conf_t *cf)
634634
{
635+
#if nginx_version >= 1011011
636+
ngx_pool_cleanup_t *cln;
637+
#endif
635638
ngx_http_echo_main_conf_t *emcf;
636639

637640
emcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_echo_main_conf_t));
@@ -643,6 +646,16 @@ ngx_http_echo_create_main_conf(ngx_conf_t *cf)
643646
* hmcf->requires_filter = 0;
644647
*/
645648

649+
#if nginx_version >= 1011011
650+
cln = ngx_pool_cleanup_add(cf->pool, 0);
651+
if (cln == NULL) {
652+
return NULL;
653+
}
654+
655+
cln->data = emcf;
656+
cln->handler = ngx_http_echo_request_headers_cleanup;
657+
#endif
658+
646659
return emcf;
647660
}
648661

src/ngx_http_echo_module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ typedef struct {
9292

9393
typedef struct {
9494
ngx_int_t requires_filter;
95+
#if nginx_version >= 1011011
96+
ngx_buf_t **busy_buf_ptrs;
97+
ngx_int_t busy_buf_ptr_count;
98+
#endif
9599
} ngx_http_echo_main_conf_t;
96100

97101

src/ngx_http_echo_request_info.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818

1919
static void ngx_http_echo_post_read_request_body(ngx_http_request_t *r);
20+
#if nginx_version >= 1011011
21+
void ngx_http_echo_request_headers_cleanup(void *data);
22+
#endif
2023

2124

2225
ngx_int_t
@@ -179,6 +182,11 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
179182
ngx_int_t i, j;
180183
ngx_buf_t *b, *first = NULL;
181184
unsigned found;
185+
#if nginx_version >= 1011011
186+
ngx_buf_t **bb;
187+
ngx_chain_t *cl;
188+
ngx_http_echo_main_conf_t *emcf;
189+
#endif
182190
ngx_connection_t *c;
183191
ngx_http_request_t *mr;
184192
ngx_http_connection_t *hc;
@@ -195,6 +203,10 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
195203
}
196204
#endif
197205

206+
#if nginx_version >= 1011011
207+
emcf = ngx_http_get_module_main_conf(r, ngx_http_echo_module);
208+
#endif
209+
198210
size = 0;
199211
b = c->buffer;
200212

@@ -215,8 +227,35 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
215227

216228
if (hc->nbusy) {
217229
b = NULL;
230+
231+
#if nginx_version >= 1011011
232+
if (hc->nbusy > emcf->busy_buf_ptr_count) {
233+
if (emcf->busy_buf_ptrs) {
234+
ngx_free(emcf->busy_buf_ptrs);
235+
}
236+
237+
emcf->busy_buf_ptrs = ngx_alloc(hc->nbusy * sizeof(ngx_buf_t *),
238+
r->connection->log);
239+
240+
if (emcf->busy_buf_ptrs == NULL) {
241+
return NGX_ERROR;
242+
}
243+
244+
emcf->busy_buf_ptr_count = hc->nbusy;
245+
}
246+
247+
bb = emcf->busy_buf_ptrs;
248+
for (cl = hc->busy; cl; cl = cl->next) {
249+
*bb++ = cl->buf;
250+
}
251+
252+
bb = emcf->busy_buf_ptrs;
253+
for (i = hc->nbusy; i > 0; i--) {
254+
b = bb[i - 1];
255+
#else
218256
for (i = 0; i < hc->nbusy; i++) {
219257
b = hc->busy[i];
258+
#endif
220259

221260
if (first == NULL) {
222261
if (mr->request_line.data >= b->pos
@@ -280,8 +319,15 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
280319
}
281320

282321
if (hc->nbusy) {
322+
323+
#if nginx_version >= 1011011
324+
bb = emcf->busy_buf_ptrs;
325+
for (i = hc->nbusy; i > 0; i--) {
326+
b = bb[i - 1];
327+
#else
283328
for (i = 0; i < hc->nbusy; i++) {
284329
b = hc->busy[i];
330+
#endif
285331

286332
if (!found) {
287333
if (b != first) {
@@ -457,4 +503,20 @@ ngx_http_echo_response_status_variable(ngx_http_request_t *r,
457503
return NGX_OK;
458504
}
459505

506+
507+
#if nginx_version >= 1011011
508+
void
509+
ngx_http_echo_request_headers_cleanup(void *data)
510+
{
511+
ngx_http_echo_main_conf_t *emcf;
512+
513+
emcf = (ngx_http_echo_main_conf_t *) data;
514+
515+
if (emcf->busy_buf_ptrs) {
516+
ngx_free(emcf->busy_buf_ptrs);
517+
emcf->busy_buf_ptrs = NULL;
518+
}
519+
}
520+
#endif
521+
460522
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_http_echo_request_info.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ ngx_int_t ngx_http_echo_request_uri_variable(ngx_http_request_t *r,
2929
ngx_int_t ngx_http_echo_response_status_variable(ngx_http_request_t *r,
3030
ngx_http_variable_value_t *v, uintptr_t data);
3131

32+
#if nginx_version >= 1011011
33+
void ngx_http_echo_request_headers_cleanup(void *data);
34+
#endif
3235

3336
#endif /* ECHO_REQUEST_INFO_H */

valgrind.suppress

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@
3636
fun:do_preload
3737
fun:dl_main
3838
}
39+
{
40+
<insert_a_suppression_name_here>
41+
Memcheck:Leak
42+
match-leak-kinds: definite
43+
fun:malloc
44+
fun:ngx_alloc
45+
fun:ngx_set_environment
46+
fun:ngx_single_process_cycle
47+
fun:main
48+
}

0 commit comments

Comments
 (0)