Skip to content

Tests: client_body_early_read directive. - #103

Open
jimf5 wants to merge 1 commit into
nginx:masterfrom
jimf5:dev/client-body-preread
Open

Tests: client_body_early_read directive.#103
jimf5 wants to merge 1 commit into
nginx:masterfrom
jimf5:dev/client-body-preread

Conversation

@jimf5

@jimf5 jimf5 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Added tests for the client_body_early_read directive introduced in PR: nginx/nginx#1641

Checklist

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

@jimf5
jimf5 requested review from arut, pluknet and route443 August 15, 2026 07:02
@jimf5 jimf5 self-assigned this Aug 15, 2026
@jimf5 jimf5 added the tests label Aug 15, 2026
@jimf5
jimf5 force-pushed the dev/client-body-preread branch from 062294f to b6bb50b Compare August 15, 2026 07:55
@sindhushiv sindhushiv moved this from New to In Review in NGINX OSS Unified Workspace Aug 17, 2026
@jimf5
jimf5 force-pushed the dev/client-body-preread branch from b6bb50b to 4d25224 Compare August 17, 2026 18:56
Comment thread client_body_early_read.t Outdated
Comment on lines +28 to +29
plan(skip_all => 'no client_body_early_read support')
unless $t->has_version('1.31.4');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces to tabs

or remove "support" to unwrap into a single line, or use $t->try_run()

also, let's drop a trailing dot in log summary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

@pluknet pluknet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with comments

@jimf5
jimf5 force-pushed the dev/client-body-preread branch 2 times, most recently from 4daf606 to 18f9433 Compare August 20, 2026 08:45
@jimf5
jimf5 force-pushed the dev/client-body-preread branch from 18f9433 to 33c136d Compare August 27, 2026 19:48
Comment thread client_body_early_read.t Outdated
server_name localhost;

client_max_body_size 256;
client_body_buffer_size 4k;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that none of the checks depend on this directive value, the only checks regarding the buffer/file go to server 8083, which has its own client_body_buffer_size 16. If I remove it, tests are passed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this line is not needed. Good catch.

Comment thread client_body_early_read.t
listen 127.0.0.1:8081;
server_name localhost;

client_body_early_read $arg_on;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we check the complex val only, which is good, however, the directive itself employs a more extensive logic:

  • 0 if we want to disable it (falsy literal)
  • multiple arguments are possible => the rule acts as OR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added explicit tests for 0 and non-0 cases

Comment thread client_body_early_read.t Outdated
'body at exact limit');
like(http_post_body('/', '0123456789' x 2, 8082), qr/ 413 /,
'server limit applies not location');
like(http_post_body('/', '0123456789' x 100, 8083), qr/ 204 /,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly are we trying to test here? If we remove client_max_body_size 0;, then this test will pass...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the test name is misleading. Renamed. The goal of this test is to confirm that intensive memory allocation does not impact system functionality or stability.

Comment thread client_body_early_read.t
}
}

server {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this server is needed at all, since 8002 is perfectly sufficient. The only difference is the client_max_body_size 100 setting within the location block, but that gets ignored in early read mode anyway. In other words, the chunked body exceeds limit and chunked body within limit cases can be moved to 8002

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

Comment thread client_body_early_read.t Outdated

like(http_post_body('/', '0123456789', 8080), qr/body:0123456789/,
'body via return');
unlike(http_post_body('/', '0123456789', 8081), qr/body:0123456789/,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd try to avoid unlike tests, since they succeed on just about anything. I would do:

like(http_post_body('/', '0123456789', 8081), qr/body:$/, 'predicate false');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense; fixed.

Comment thread client_body_early_read.t Outdated
unlike(http_post_body('/', '0123456789', 8081), qr/body:0123456789/,
'no early read - body not available');
like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/,
'ealy read - body available');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ealy -> early

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread client_body_early_read.t
'no early read - body not available');
like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/,
'ealy read - body available');
like(http_post_body('/proxy', '0123456789', 8080),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

during feature discussion, we mentioned this directive isn't needed for proxy_pass, meaning you'll get the body in the content phase anyway. So, even if you remove the directive, this test (and friends) will still pass...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is intended to ensure that no regressions have been introduced.

@github-project-automation github-project-automation Bot moved this from In Review to In Progress in NGINX OSS Unified Workspace Aug 27, 2026
Comment thread client_body_early_read.t Outdated
qr/X-Body: 0123456789\x0d?$/ms, 'body via proxy');
like(http_get('/'), qr/ 200 /, 'no body');
like(http_post_body('/', '', 8080), qr/body:$/, 'empty body');
like(http_post_body('/', '0123456789', 8080), qr/ 200 /,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same test as body via return, but the regex is different, but body via return is only possible with 200 ok => can be removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, removed

Comment thread client_body_early_read.t
like(http_post_body('/', '', 8080), qr/body:$/, 'empty body');
like(http_post_body('/', '0123456789', 8080), qr/ 200 /,
'body within limit');
like(http_post_body('/', 'x' x 300, 8080), qr/ 413 /,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of server limit applies not location. The location block L:51 does not have its own limit => the location value matches the server value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated tests to show directive inheritance.

Comment thread client_body_early_read.t Outdated
'body within limit');
like(http_post_body('/', 'x' x 300, 8080), qr/ 413 /,
'body exceeds limit');
like(http_post_body('/', 'x' x 256, 8080), qr/ 200 /,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd replace qr/ 200 / to qr/body:x{256}/.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed

Comment thread client_body_early_read.t Outdated
'early read body reaches location');
like(http_post_body('/rewrite', 'HELLO', 8080), qr/loc1:HELLO/,
'early read body survives rewrite');
like(http_post_body('/echo', 'TESTBODY', 8080), qr/echo:TESTBODY/,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it is also redundant, since server 8085 inherits client_body_early_read 1 from http block and proxy_pass passes the body upstream in any case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. No, this test isn't needed.

Comment thread client_body_early_read.t
Comment on lines +190 to +191
like($r, qr/ 413 /, 'expect continue too large');
unlike($r, qr/100 Continue/, 'expect continue too large - no 100');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same remark as for body exceeds limit, It looks like you need to send the request to a location with a limit higher than the server limit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's intended to verify that no 100 status in the 413 response.

Comment thread client_body_early_read.t Outdated
like($r, qr/ 413 /, 'expect continue too large');
unlike($r, qr/100 Continue/, 'expect continue too large - no 100');

like(http_post_body('/loc1', 'HELLO', 8080), qr/loc1:HELLO/,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite see the fundamental difference compared to body via return tc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, me too. Removed.

@jimf5
jimf5 force-pushed the dev/client-body-preread branch from f250d85 to b6c8564 Compare August 30, 2026 19:41

@jimf5 jimf5 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@route443 Thanks for the review

Comment thread client_body_early_read.t Outdated
server_name localhost;

client_max_body_size 256;
client_body_buffer_size 4k;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this line is not needed. Good catch.

Comment thread client_body_early_read.t
listen 127.0.0.1:8081;
server_name localhost;

client_body_early_read $arg_on;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added explicit tests for 0 and non-0 cases

Comment thread client_body_early_read.t
}
}

server {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

Comment thread client_body_early_read.t Outdated
unlike(http_post_body('/', '0123456789', 8081), qr/body:0123456789/,
'no early read - body not available');
like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/,
'ealy read - body available');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread client_body_early_read.t
'no early read - body not available');
like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/,
'ealy read - body available');
like(http_post_body('/proxy', '0123456789', 8080),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is intended to ensure that no regressions have been introduced.

Comment thread client_body_early_read.t Outdated
'body within limit');
like(http_post_body('/', 'x' x 300, 8080), qr/ 413 /,
'body exceeds limit');
like(http_post_body('/', 'x' x 256, 8080), qr/ 200 /,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed

Comment thread client_body_early_read.t Outdated
like($r, qr/ 413 /, 'expect continue too large');
unlike($r, qr/100 Continue/, 'expect continue too large - no 100');

like(http_post_body('/loc1', 'HELLO', 8080), qr/loc1:HELLO/,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, me too. Removed.

Comment thread client_body_early_read.t Outdated
'early read body reaches location');
like(http_post_body('/rewrite', 'HELLO', 8080), qr/loc1:HELLO/,
'early read body survives rewrite');
like(http_post_body('/echo', 'TESTBODY', 8080), qr/echo:TESTBODY/,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. No, this test isn't needed.

Comment thread client_body_early_read.t Outdated
'body at exact limit');
like(http_post_body('/', '0123456789' x 2, 8082), qr/ 413 /,
'server limit applies not location');
like(http_post_body('/', '0123456789' x 100, 8083), qr/ 204 /,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the test name is misleading. Renamed. The goal of this test is to confirm that intensive memory allocation does not impact system functionality or stability.

Comment thread client_body_early_read.t
Comment on lines +190 to +191
like($r, qr/ 413 /, 'expect continue too large');
unlike($r, qr/100 Continue/, 'expect continue too large - no 100');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's intended to verify that no 100 status in the 413 response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants