Skip to content

Commit f15ed16

Browse files
authored
Merge pull request chobits#59 from chobits/for_pull_request
simplify patch: move CONNECT request checking logic to module source
2 parents c836d29 + 6838570 commit f15ed16

File tree

5 files changed

+43
-149
lines changed

5 files changed

+43
-149
lines changed

ngx_http_proxy_connect_module.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef struct {
8080
} ngx_http_proxy_connect_ctx_t;
8181

8282

83+
static ngx_int_t ngx_http_proxy_connect_init(ngx_conf_t *cf);
8384
static ngx_int_t ngx_http_proxy_connect_add_variables(ngx_conf_t *cf);
8485
static ngx_int_t ngx_http_proxy_connect_connect_addr_variable(
8586
ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
@@ -170,7 +171,7 @@ static ngx_command_t ngx_http_proxy_connect_commands[] = {
170171

171172
static ngx_http_module_t ngx_http_proxy_connect_module_ctx = {
172173
ngx_http_proxy_connect_add_variables, /* preconfiguration */
173-
NULL, /* postconfiguration */
174+
ngx_http_proxy_connect_init, /* postconfiguration */
174175

175176
NULL, /* create main configuration */
176177
NULL, /* init main configuration */
@@ -1568,11 +1569,14 @@ ngx_http_proxy_connect_allow(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
15681569
static char *
15691570
ngx_http_proxy_connect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
15701571
{
1571-
ngx_http_core_loc_conf_t *clcf;
1572+
ngx_http_core_loc_conf_t *clcf;
1573+
ngx_http_proxy_connect_loc_conf_t *pclcf;
15721574

15731575
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
15741576
clcf->handler = ngx_http_proxy_connect_handler;
1575-
clcf->accept_connect = 1;
1577+
1578+
pclcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_proxy_connect_module);
1579+
pclcf->accept_connect = 1;
15761580

15771581
return NGX_CONF_OK;
15781582
}
@@ -1970,3 +1974,39 @@ ngx_http_proxy_connect_add_variables(ngx_conf_t *cf)
19701974

19711975
return NGX_OK;
19721976
}
1977+
1978+
1979+
static ngx_int_t
1980+
ngx_http_proxy_connect_post_read_handler(ngx_http_request_t *r)
1981+
{
1982+
ngx_http_proxy_connect_loc_conf_t *pclcf;
1983+
1984+
pclcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_connect_module);
1985+
1986+
if (r->method == NGX_HTTP_CONNECT && !pclcf->accept_connect) {
1987+
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1988+
"client sent connect method");
1989+
return NGX_HTTP_BAD_REQUEST;
1990+
}
1991+
1992+
return NGX_DECLINED;
1993+
}
1994+
1995+
1996+
static ngx_int_t
1997+
ngx_http_proxy_connect_init(ngx_conf_t *cf)
1998+
{
1999+
ngx_http_core_main_conf_t *cmcf;
2000+
ngx_http_handler_pt *h;
2001+
2002+
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
2003+
2004+
h = ngx_array_push(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers);
2005+
if (h == NULL) {
2006+
return NGX_ERROR;
2007+
}
2008+
2009+
*h = ngx_http_proxy_connect_post_read_handler;
2010+
2011+
return NGX_OK;
2012+
}

patch/proxy_connect.patch

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,6 @@ diff -r c5f81dcf97a7 src/http/ngx_http_core_module.c
4444
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
4545

4646
if (clcf->try_files == NULL) {
47-
diff -r c5f81dcf97a7 src/http/ngx_http_core_module.h
48-
--- a/src/http/ngx_http_core_module.h Thu Mar 03 21:14:19 2016 +0300
49-
+++ b/src/http/ngx_http_core_module.h Thu Mar 10 15:41:41 2016 +0800
50-
@@ -343,6 +343,10 @@
51-
#endif
52-
#endif
53-
54-
+#if (NGX_HTTP_PROXY_CONNECT)
55-
+ unsigned accept_connect:1;
56-
+#endif
57-
+
58-
ngx_http_location_tree_node_t *static_locations;
59-
#if (NGX_PCRE)
60-
ngx_http_core_loc_conf_t **regex_locations;
6147
diff -r c5f81dcf97a7 src/http/ngx_http_parse.c
6248
--- a/src/http/ngx_http_parse.c Thu Mar 03 21:14:19 2016 +0300
6349
+++ b/src/http/ngx_http_parse.c Thu Mar 10 15:41:41 2016 +0800
@@ -293,28 +279,6 @@ diff -r c5f81dcf97a7 src/http/ngx_http_request.c
293279
if (r->host_start) {
294280
r->host_start = new + (r->host_start - old);
295281
if (r->host_end) {
296-
@@ -1838,6 +1898,21 @@
297-
298-
c = r->connection;
299-
300-
+#if (NGX_HTTP_PROXY_CONNECT)
301-
+
302-
+ ngx_http_core_loc_conf_t *clcf;
303-
+
304-
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
305-
+
306-
+ if (r->method == NGX_HTTP_CONNECT && !clcf->accept_connect) {
307-
+ ngx_log_error(NGX_LOG_INFO, c->log, 0,
308-
+ "client sent connect method");
309-
+ ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
310-
+ return;
311-
+ }
312-
+
313-
+#endif
314-
+
315-
#if (NGX_HTTP_SSL)
316-
317-
if (r->http_connection->ssl) {
318282
diff -r c5f81dcf97a7 src/http/ngx_http_request.h
319283
--- a/src/http/ngx_http_request.h Thu Mar 03 21:14:19 2016 +0300
320284
+++ b/src/http/ngx_http_request.h Thu Mar 10 15:41:41 2016 +0800

patch/proxy_connect_1014.patch

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ index 5951571..09f3188 100644
3131
rc = ngx_http_core_find_location(r);
3232

3333
if (rc == NGX_ERROR) {
34-
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
35-
index a6128b5..c21230b 100644
36-
--- a/src/http/ngx_http_core_module.h
37-
+++ b/src/http/ngx_http_core_module.h
38-
@@ -315,6 +315,10 @@ struct ngx_http_core_loc_conf_s {
39-
unsigned gzip_disable_degradation:2;
40-
#endif
41-
42-
+#if (NGX_HTTP_PROXY_CONNECT)
43-
+ unsigned accept_connect:1;
44-
+#endif
45-
+
46-
ngx_http_location_tree_node_t *static_locations;
47-
#if (NGX_PCRE)
48-
ngx_http_core_loc_conf_t **regex_locations;
4934
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
5035
index 844054c..1b5adf9 100644
5136
--- a/src/http/ngx_http_parse.c
@@ -283,28 +268,6 @@ index 5668bf4..430a67f 100644
283268
if (r->host_start) {
284269
r->host_start = new + (r->host_start - old);
285270
if (r->host_end) {
286-
@@ -1876,6 +1936,21 @@ ngx_http_process_request(ngx_http_request_t *r)
287-
288-
c = r->connection;
289-
290-
+#if (NGX_HTTP_PROXY_CONNECT)
291-
+
292-
+ ngx_http_core_loc_conf_t *clcf;
293-
+
294-
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
295-
+
296-
+ if (r->method == NGX_HTTP_CONNECT && !clcf->accept_connect) {
297-
+ ngx_log_error(NGX_LOG_INFO, c->log, 0,
298-
+ "client sent connect method");
299-
+ ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
300-
+ return;
301-
+ }
302-
+
303-
+#endif
304-
+
305-
#if (NGX_HTTP_SSL)
306-
307-
if (r->http_connection->ssl) {
308271
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
309272
index 421004a..f07d4e7 100644
310273
--- a/src/http/ngx_http_request.h

patch/proxy_connect_rewrite.patch

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ diff -r c5f81dcf97a7 src/http/ngx_http_core_module.c
3030
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
3131

3232
if (clcf->try_files == NULL) {
33-
diff -r c5f81dcf97a7 src/http/ngx_http_core_module.h
34-
--- a/src/http/ngx_http_core_module.h Thu Mar 03 21:14:19 2016 +0300
35-
+++ b/src/http/ngx_http_core_module.h Thu Mar 10 15:41:41 2016 +0800
36-
@@ -343,6 +343,10 @@
37-
#endif
38-
#endif
39-
40-
+#if (NGX_HTTP_PROXY_CONNECT)
41-
+ unsigned accept_connect:1;
42-
+#endif
43-
+
44-
ngx_http_location_tree_node_t *static_locations;
45-
#if (NGX_PCRE)
46-
ngx_http_core_loc_conf_t **regex_locations;
4733
diff -r c5f81dcf97a7 src/http/ngx_http_parse.c
4834
--- a/src/http/ngx_http_parse.c Thu Mar 03 21:14:19 2016 +0300
4935
+++ b/src/http/ngx_http_parse.c Thu Mar 10 15:41:41 2016 +0800
@@ -279,28 +265,6 @@ diff -r c5f81dcf97a7 src/http/ngx_http_request.c
279265
if (r->host_start) {
280266
r->host_start = new + (r->host_start - old);
281267
if (r->host_end) {
282-
@@ -1838,6 +1898,21 @@
283-
284-
c = r->connection;
285-
286-
+#if (NGX_HTTP_PROXY_CONNECT)
287-
+
288-
+ ngx_http_core_loc_conf_t *clcf;
289-
+
290-
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
291-
+
292-
+ if (r->method == NGX_HTTP_CONNECT && !clcf->accept_connect) {
293-
+ ngx_log_error(NGX_LOG_INFO, c->log, 0,
294-
+ "client sent connect method");
295-
+ ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
296-
+ return;
297-
+ }
298-
+
299-
+#endif
300-
+
301-
#if (NGX_HTTP_SSL)
302-
303-
if (r->http_connection->ssl) {
304268
diff -r c5f81dcf97a7 src/http/ngx_http_request.h
305269
--- a/src/http/ngx_http_request.h Thu Mar 03 21:14:19 2016 +0300
306270
+++ b/src/http/ngx_http_request.h Thu Mar 10 15:41:41 2016 +0800

patch/proxy_connect_rewrite_1014.patch

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@ index 5951571..e950f50 100644
1717
rc = ngx_http_core_find_location(r);
1818

1919
if (rc == NGX_ERROR) {
20-
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
21-
index a6128b5..c21230b 100644
22-
--- a/src/http/ngx_http_core_module.h
23-
+++ b/src/http/ngx_http_core_module.h
24-
@@ -315,6 +315,10 @@ struct ngx_http_core_loc_conf_s {
25-
unsigned gzip_disable_degradation:2;
26-
#endif
27-
28-
+#if (NGX_HTTP_PROXY_CONNECT)
29-
+ unsigned accept_connect:1;
30-
+#endif
31-
+
32-
ngx_http_location_tree_node_t *static_locations;
33-
#if (NGX_PCRE)
34-
ngx_http_core_loc_conf_t **regex_locations;
3520
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
3621
index 844054c..1b5adf9 100644
3722
--- a/src/http/ngx_http_parse.c
@@ -269,28 +254,6 @@ index 5668bf4..430a67f 100644
269254
if (r->host_start) {
270255
r->host_start = new + (r->host_start - old);
271256
if (r->host_end) {
272-
@@ -1876,6 +1936,21 @@ ngx_http_process_request(ngx_http_request_t *r)
273-
274-
c = r->connection;
275-
276-
+#if (NGX_HTTP_PROXY_CONNECT)
277-
+
278-
+ ngx_http_core_loc_conf_t *clcf;
279-
+
280-
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
281-
+
282-
+ if (r->method == NGX_HTTP_CONNECT && !clcf->accept_connect) {
283-
+ ngx_log_error(NGX_LOG_INFO, c->log, 0,
284-
+ "client sent connect method");
285-
+ ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
286-
+ return;
287-
+ }
288-
+
289-
+#endif
290-
+
291-
#if (NGX_HTTP_SSL)
292-
293-
if (r->http_connection->ssl) {
294257
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
295258
index 421004a..f07d4e7 100644
296259
--- a/src/http/ngx_http_request.h

0 commit comments

Comments
 (0)