Skip to content

Tests: request body discard and error handling#31

Draft
dekobon wants to merge 3 commits intonginx:masterfrom
dekobon:cherry/body-discard-tests
Draft

Tests: request body discard and error handling#31
dekobon wants to merge 3 commits intonginx:masterfrom
dekobon:cherry/body-discard-tests

Conversation

@dekobon
Copy link

@dekobon dekobon commented Feb 20, 2026

Proposed changes

Backports test coverage from freenginx for the request body error-handling improvements in the companion nginx PR on branch cherry/request-body-fixed-segfault-on-early-errors.

These tests exercise error_page 413 handling, $content_length behaviour, and proxy body forwarding when the request body has been discarded or encountered errors — across HTTP/1.x, HTTP/2, and HTTP/3. They also adjust an existing test (http_headers_multi.t) for a $content_length semantic change introduced by the nginx commits.

See the nginx-devel mailing list thread for the original bug report that motivated these changes.

Commits (in application order)

# Commit Description
1 6647488 Adjust http_headers_multi.t so $content_length is evaluated before body discard, since the variable is no longer available after discard.
2 cb3152b Add body_discard.t, h2_request_body_discard.t, and h3_request_body_discard.t covering error_page 413, $content_length, and proxy forwarding after body discard.
3 c60e1f1 Increase sleep delays in body discard tests from 0.1s to 0.2s to fix flaky failures on slow hosts.

Checklist

Before creating a PR, run through this checklist and mark each as complete:

  • I have read the contributing guidelines.
  • I have verified the tests pass with the companion nginx changes applied.

mdounin and others added 3 commits February 19, 2026 23:30
The $content_length variable is going to be not available after discarding
the request body.  As such, the relevant location is now proxied, so the
request body is not discarded.

Co-Authored-By: Elijah Zupancic <e.zupancic@f5.com>
Cherry-Picked-From: https://freenginx.org/hg/nginx-tests/rev/e44ee916b9598eaf805aaa9aa7afaa35db2140a5
The client_max_body_size limit should be ignored when the request body
is already discarded.  In HTTP/1.x, this is done by checking the
r->discard_body flag when the body is being discarded, and because
r->headers_in.content_length_n is 0 when it's already discarded.  This,
however, does not happen with HTTP/2 and HTTP/3, and therefore
"error_page 413" does not work without relaxing the limit.

Further, with proxy_pass, r->headers_in.content_length_n is used to determine
length of the request body, and therefore is not correct if discarding of
the request body isn't yet complete.  While discarding the request body,
r->headers_in.content_length_n contains the rest of the body to discard
(or, in case of chunked request body, the rest of the current chunk to
discard).

Similarly, the $content_length variable uses r->headers_in.content_length
if available, and also incorrect.  The $content_length variable is used
when proxying with fastcgi_pass, grpc_pass, and uwsgi_pass (scgi_pass uses
the value calculated based on the actual request body buffers, and therefore
works correctly).

Co-Authored-By: Elijah Zupancic <e.zupancic@f5.com>
Cherry-Picked-From: https://freenginx.org/hg/nginx-tests/rev/fe6f22da53ec760f7ab138d1d32b7a03ea7bdea3
At least h3_request_body_discard.t occasionally fails on slow hosts
due to too short delays, and using longer delays fixes this.

Co-Authored-By: Elijah Zupancic <e.zupancic@f5.com>
Cherry-Picked-From: https://freenginx.org/hg/nginx-tests/rev/250fb78dd27079ed3cb3fd5d3b7a0132ad2ce89f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants