annotate debug_connection.t @ 1961:fe6f22da53ec default tip

Tests: tests for usage of discarded body. 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).
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:55:50 +0300
parents fcd65708672d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
303
ad51e58c2d7a Tests: fixed typo in copyright.
Sergey Kandaurov <pluknet@nginx.com>
parents: 301
diff changeset
3 # (C) Nginx, Inc.
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # Tests for debug_connection.
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 ###############################################################################
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 use warnings;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use strict;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use Test::More;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 use lib 'lib';
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use Test::Nginx;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 ###############################################################################
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 select STDERR; $| = 1;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
1170
cf14cfe9ec8c Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http --with-debug proxy/);
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 $t->write_file_expand('nginx.conf', <<'EOF');
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 debug_connection ::1;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 error_log %%TESTDIR%%/debug1.log alert;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 error_log %%TESTDIR%%/debug2.log alert;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
43 listen 127.0.0.1:8080;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
44 listen [::1]:%%PORT_8080%%;
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 server_name localhost;
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 location /debug {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
48 proxy_pass http://[::1]:%%PORT_8080%%/;
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 }
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 EOF
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
1190
fcd65708672d Tests: let tests pass on travis-ci VMs with disabled IPv6 loopback.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1171
diff changeset
55 $t->try_run('no inet6 support')->plan(5);
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 ###############################################################################
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 http_get('/');
519
089c4174e269 Tests: reduced race in debug_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 467
diff changeset
60
089c4174e269 Tests: reduced race in debug_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 467
diff changeset
61 select undef, undef, undef, 0.1;
467
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 397
diff changeset
62 is($t->read_file('debug1.log'), '', 'no debug_connection file 1');
827
df3ab213fb0f Tests: typo.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 519
diff changeset
63 is($t->read_file('debug2.log'), '', 'no debug_connection file 2');
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 http_get('/debug');
519
089c4174e269 Tests: reduced race in debug_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 467
diff changeset
66
089c4174e269 Tests: reduced race in debug_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 467
diff changeset
67 select undef, undef, undef, 0.1;
467
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 397
diff changeset
68 like($t->read_file('debug1.log'), qr/\[debug\]/, 'debug_connection file 1');
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 397
diff changeset
69 like($t->read_file('debug2.log'), qr/\[debug\]/, 'debug_connection file 2');
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 397
diff changeset
70 is($t->read_file('debug1.log'), $t->read_file('debug2.log'),
301
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 'debug_connection file1 file2 match');
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
a107552ac714 Tests: added tests for debug_connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 ###############################################################################