@@ -80,6 +80,7 @@ typedef struct {
80
80
} ngx_http_proxy_connect_ctx_t ;
81
81
82
82
83
+ static ngx_int_t ngx_http_proxy_connect_init (ngx_conf_t * cf );
83
84
static ngx_int_t ngx_http_proxy_connect_add_variables (ngx_conf_t * cf );
84
85
static ngx_int_t ngx_http_proxy_connect_connect_addr_variable (
85
86
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[] = {
170
171
171
172
static ngx_http_module_t ngx_http_proxy_connect_module_ctx = {
172
173
ngx_http_proxy_connect_add_variables , /* preconfiguration */
173
- NULL , /* postconfiguration */
174
+ ngx_http_proxy_connect_init , /* postconfiguration */
174
175
175
176
NULL , /* create main configuration */
176
177
NULL , /* init main configuration */
@@ -1568,11 +1569,14 @@ ngx_http_proxy_connect_allow(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1568
1569
static char *
1569
1570
ngx_http_proxy_connect (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1570
1571
{
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 ;
1572
1574
1573
1575
clcf = ngx_http_conf_get_module_loc_conf (cf , ngx_http_core_module );
1574
1576
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 ;
1576
1580
1577
1581
return NGX_CONF_OK ;
1578
1582
}
@@ -1970,3 +1974,39 @@ ngx_http_proxy_connect_add_variables(ngx_conf_t *cf)
1970
1974
1971
1975
return NGX_OK ;
1972
1976
}
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
+ }
0 commit comments