Skip to content

Commit

Permalink
make it return the same status code as nginx does to refuse CONNECT m…
Browse files Browse the repository at this point in the history
…ethod

If proxy_connect module is not enabled, the server will return a 405 status code instead of 400.
  • Loading branch information
chobits committed Feb 7, 2023
1 parent 0bc35f6 commit 9609184
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ngx_http_proxy_connect_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ ngx_http_proxy_connect_post_read_handler(ngx_http_request_t *r)
if (!pclcf->accept_connect) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
"proxy_connect: client sent connect method");
return NGX_HTTP_BAD_REQUEST;
return NGX_HTTP_NOT_ALLOWED;
}

/* init ctx */
Expand Down
2 changes: 1 addition & 1 deletion t/http_proxy_connect.t
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ like(http_connect_request('www.no-dns-reply.com', '80', '/'), qr/502/, '200 Conn
like(http_connect_request('127.0.0.1', '9999', '/'), qr/403/, '200 Connection Established not allowed port');
like(http_get('/'), qr/backend server/, 'Get method: proxy_pass');
like(http_get('/hello'), qr/world/, 'Get method: return 200');
like(http_connect_request('forbidden.example.com', '8080', '/'), qr/400 Bad Request/, 'forbid CONNECT request without proxy_connect command enabled');
like(http_connect_request('forbidden.example.com', '8080', '/'), qr/405 Not Allowed/, 'forbid CONNECT request without proxy_connect command enabled');

# proxy_remote_address directive supports dynamic domain resolving.
like(http_connect_request('proxy-remote-address-resolve-domain.com', '8081', '/'),
Expand Down

0 comments on commit 9609184

Please sign in to comment.