Request body: improved handling of incorrect chunked request body.
While discarding chunked request body in some cases after detecting
request body corruption no error was returned, while it was possible
to correctly return 400 Bad Request. If error is detected too late,
make sure to properly close connection.
Additionally, in ngx_http_special_response_handler() don't return body
of 500 Internal Server Error to a client if ngx_http_discard_request_body()
fails, but disable keepalive and continue.
Maxim Dounin
9 years ago
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
473 | if (ngx_http_read_discarded_request_body(r) == NGX_OK) { | |
473 | rc = ngx_http_read_discarded_request_body(r); | |
474 | ||
475 | if (rc == NGX_OK) { | |
474 | 476 | r->lingering_close = 0; |
475 | 477 | return NGX_OK; |
476 | 478 | } |
477 | 479 | |
478 | /* == NGX_AGAIN */ | |
480 | if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
481 | return rc; | |
482 | } | |
483 | ||
484 | /* rc == NGX_AGAIN */ | |
479 | 485 | |
480 | 486 | r->read_event_handler = ngx_http_discarded_request_body_handler; |
481 | 487 | |
532 | 538 | return; |
533 | 539 | } |
534 | 540 | |
541 | if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
542 | c->error = 1; | |
543 | ngx_http_finalize_request(r, NGX_ERROR); | |
544 | return; | |
545 | } | |
546 | ||
535 | 547 | /* rc == NGX_AGAIN */ |
536 | 548 | |
537 | 549 | if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
605 | 617 | rc = ngx_http_discard_request_body_filter(r, &b); |
606 | 618 | |
607 | 619 | if (rc != NGX_OK) { |
608 | r->connection->error = 1; | |
609 | return NGX_OK; | |
620 | return rc; | |
610 | 621 | } |
611 | 622 | } |
612 | 623 | } |