# HG changeset patch # User Maxim Dounin # Date 1423488707 -10800 # Node ID 04788ce8dae79d55962a74b89d667597033e82e2 # Parent 17c333645ebba8815c5bc9eccd3ce26cddfd6fd1 Close connection on errors. diff --git a/ngx_http_catch_body_filter_module.c b/ngx_http_catch_body_filter_module.c --- a/ngx_http_catch_body_filter_module.c +++ b/ngx_http_catch_body_filter_module.c @@ -94,6 +94,16 @@ ngx_http_catch_body_filter(ngx_http_requ if (*p == 'X') { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "catch body: found"); + + /* + * As we return NGX_HTTP_FORBIDDEN, the r->keepalive flag + * won't be reset by ngx_http_special_response_handler(). + * Make sure to reset it to prevent processing of unread + * parts of the request body. + */ + + r->keepalive = 0; + return NGX_HTTP_FORBIDDEN; } } diff --git a/t/catch_body.t b/t/catch_body.t --- a/t/catch_body.t +++ b/t/catch_body.t @@ -62,18 +62,18 @@ like(get_body('/', '123456', '12345X'), 'second rejected'); like(get_body('/', '123456' x 1024, '12345X6789' x 1024, '123456' x 1024), - qr/200 OK.*403 Forbidden.*200 OK/ms, - 'accepted rejected accepted'); + qr/200 OK.*403 Forbidden(?!.*400 Bad)/ms, + 'accepted rejected ignored'); # pipelining with chunked like(get_chunked('/', '123456', '12345X'), qr/200 OK.*403 Forbidden/ms, - 'second rejected'); + 'chunked second rejected'); like(get_chunked('/', '123456', '12345X6789', '123456'), - qr/200 OK.*403 Forbidden.*200 OK/ms, - 'accepted rejected accepted'); + qr/200 OK.*403 Forbidden(?!.*400 Bad)/ms, + 'chunked accepted rejected ignored'); ###############################################################################