aboutsummaryrefslogtreecommitdiffstats
path: root/main/nginx/echo-nginx-module~fix-nginx-1.12.patch
blob: 9f1af70f0704642bc4a2e2540324ae15cb88a0c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
From 7740e11558b530b66b469c657576f5280b7cdb1b Mon Sep 17 00:00:00 2001
From: Andrei Belov <defanator@gmail.com>
Date: Wed, 22 Mar 2017 08:43:30 +0300
Subject: [PATCH] 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 openresty/echo-nginx-module#64

See also:
http://hg.nginx.org/nginx/rev/e662cbf1b932

Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>

Patch-Origin: Upstream's repository, master branch.
---
 src/ngx_http_echo_module.c       | 13 +++++++++
 src/ngx_http_echo_module.h       |  4 +++
 src/ngx_http_echo_request_info.c | 62 ++++++++++++++++++++++++++++++++++++++++
 src/ngx_http_echo_request_info.h |  3 ++
 valgrind.suppress                | 10 +++++++
 5 files changed, 92 insertions(+)

diff --git a/src/ngx_http_echo_module.c b/src/ngx_http_echo_module.c
index ae70479..8d736d7 100644
--- a/src/ngx_http_echo_module.c
+++ b/src/ngx_http_echo_module.c
@@ -632,6 +632,9 @@ ngx_http_echo_echo_exec(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 static void *
 ngx_http_echo_create_main_conf(ngx_conf_t *cf)
 {
+#if nginx_version >= 1011011
+    ngx_pool_cleanup_t           *cln;
+#endif
     ngx_http_echo_main_conf_t    *emcf;
 
     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)
      *      hmcf->requires_filter = 0;
      */
 
+#if nginx_version >= 1011011
+    cln = ngx_pool_cleanup_add(cf->pool, 0);
+    if (cln == NULL) {
+        return NULL;
+    }
+
+    cln->data = emcf;
+    cln->handler = ngx_http_echo_request_headers_cleanup;
+#endif
+
     return emcf;
 }
 
diff --git a/src/ngx_http_echo_module.h b/src/ngx_http_echo_module.h
index 2d212c3..ce0a305 100644
--- a/src/ngx_http_echo_module.h
+++ b/src/ngx_http_echo_module.h
@@ -92,6 +92,10 @@ typedef struct {
 
 typedef struct {
     ngx_int_t       requires_filter;
+#if nginx_version >= 1011011
+    ngx_buf_t     **busy_buf_ptrs;
+    ngx_int_t       busy_buf_ptr_count;
+#endif
 } ngx_http_echo_main_conf_t;
 
 
diff --git a/src/ngx_http_echo_request_info.c b/src/ngx_http_echo_request_info.c
index d28ec4d..7dd3683 100644
--- a/src/ngx_http_echo_request_info.c
+++ b/src/ngx_http_echo_request_info.c
@@ -17,6 +17,9 @@
 
 
 static void ngx_http_echo_post_read_request_body(ngx_http_request_t *r);
+#if nginx_version >= 1011011
+void ngx_http_echo_request_headers_cleanup(void *data);
+#endif
 
 
 ngx_int_t
@@ -179,6 +182,11 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
     ngx_int_t                    i, j;
     ngx_buf_t                   *b, *first = NULL;
     unsigned                     found;
+#if nginx_version >= 1011011
+    ngx_buf_t                  **bb;
+    ngx_chain_t                 *cl;
+    ngx_http_echo_main_conf_t   *emcf;
+#endif
     ngx_connection_t            *c;
     ngx_http_request_t          *mr;
     ngx_http_connection_t       *hc;
@@ -195,6 +203,10 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
     }
 #endif
 
+#if nginx_version >= 1011011
+    emcf = ngx_http_get_module_main_conf(r, ngx_http_echo_module);
+#endif
+
     size = 0;
     b = c->buffer;
 
@@ -215,8 +227,35 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
 
     if (hc->nbusy) {
         b = NULL;
+
+#if nginx_version >= 1011011
+        if (hc->nbusy > emcf->busy_buf_ptr_count) {
+            if (emcf->busy_buf_ptrs) {
+                ngx_free(emcf->busy_buf_ptrs);
+            }
+
+            emcf->busy_buf_ptrs = ngx_alloc(hc->nbusy * sizeof(ngx_buf_t *),
+                                            r->connection->log);
+
+            if (emcf->busy_buf_ptrs == NULL) {
+                return NGX_ERROR;
+            }
+
+            emcf->busy_buf_ptr_count = hc->nbusy;
+        }
+
+        bb = emcf->busy_buf_ptrs;
+        for (cl = hc->busy; cl; cl = cl->next) {
+            *bb++ = cl->buf;
+        }
+
+        bb = emcf->busy_buf_ptrs;
+        for (i = hc->nbusy; i > 0; i--) {
+            b = bb[i - 1];
+#else
         for (i = 0; i < hc->nbusy; i++) {
             b = hc->busy[i];
+#endif
 
             if (first == NULL) {
                 if (mr->request_line.data >= b->pos
@@ -280,8 +319,15 @@ ngx_http_echo_client_request_headers_variable(ngx_http_request_t *r,
     }
 
     if (hc->nbusy) {
+
+#if nginx_version >= 1011011
+        bb = emcf->busy_buf_ptrs;
+        for (i = hc->nbusy; i > 0; i--) {
+            b = bb[i - 1];
+#else
         for (i = 0; i < hc->nbusy; i++) {
             b = hc->busy[i];
+#endif
 
             if (!found) {
                 if (b != first) {
@@ -457,4 +503,20 @@ ngx_http_echo_response_status_variable(ngx_http_request_t *r,
     return NGX_OK;
 }
 
+
+#if nginx_version >= 1011011
+void
+ngx_http_echo_request_headers_cleanup(void *data)
+{
+    ngx_http_echo_main_conf_t  *emcf;
+
+    emcf = (ngx_http_echo_main_conf_t *) data;
+
+    if (emcf->busy_buf_ptrs) {
+        ngx_free(emcf->busy_buf_ptrs);
+        emcf->busy_buf_ptrs = NULL;
+    }
+}
+#endif
+
 /* vi:set ft=c ts=4 sw=4 et fdm=marker: */
diff --git a/src/ngx_http_echo_request_info.h b/src/ngx_http_echo_request_info.h
index 3b3713b..aa5730b 100644
--- a/src/ngx_http_echo_request_info.h
+++ b/src/ngx_http_echo_request_info.h
@@ -29,5 +29,8 @@ ngx_int_t ngx_http_echo_request_uri_variable(ngx_http_request_t *r,
 ngx_int_t ngx_http_echo_response_status_variable(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 
+#if nginx_version >= 1011011
+void ngx_http_echo_request_headers_cleanup(void *data);
+#endif
 
 #endif /* ECHO_REQUEST_INFO_H */
diff --git a/valgrind.suppress b/valgrind.suppress
index 0f8e871..d4bfe63 100644
--- a/valgrind.suppress
+++ b/valgrind.suppress
@@ -36,3 +36,13 @@
    fun:do_preload
    fun:dl_main
 }
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   match-leak-kinds: definite
+   fun:malloc
+   fun:ngx_alloc
+   fun:ngx_set_environment
+   fun:ngx_single_process_cycle
+   fun:main
+}