annotate worker_shutdown_timeout_proxy_upgrade.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 97c8280de681
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1246
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for worker_shutdown_timeout directive with http proxy upgrade stub.
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use IO::Select;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 ###############################################################################
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(2)
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 ->write_file_expand('nginx.conf', <<'EOF');
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 daemon off;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 worker_shutdown_timeout 10ms;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 http {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 server {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 listen 127.0.0.1:8080;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server_name localhost;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 location / {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 proxy_pass http://127.0.0.1:8081;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 proxy_http_version 1.1;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 proxy_set_header Upgrade foo;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 proxy_set_header Connection Upgrade;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 EOF
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 $t->run_daemon(\&http_daemon);
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 $t->run()->waitforsocket('127.0.0.1:' . port(8081));
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 ###############################################################################
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 my $s = http(<<EOF, start => 1);
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 GET / HTTP/1.1
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 Host: localhost
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 Upgrade: foo
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 Connection: Upgrade
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 EOF
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 my ($sel, $buf) = IO::Select->new($s);
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 if ($sel->can_read(5)) {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 $s->sysread($buf, 1024);
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 log_in($buf);
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 };
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 like($buf, qr!HTTP/1.1 101!, 'upgraded connection');
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 $t->reload();
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 ok($sel->can_read(3), 'upgraded connection shutdown');
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 undef $s;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 ###############################################################################
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 sub http_daemon {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 my $server = IO::Socket::INET->new(
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 Proto => 'tcp',
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 LocalHost => '127.0.0.1:' . port(8081),
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 Listen => 5,
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 Reuse => 1
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 )
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 or die "Can't create listening socket: $!\n";
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 local $SIG{PIPE} = 'IGNORE';
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my $client;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 while ($client = $server->accept()) {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 $client->autoflush(1);
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 my $headers = '';
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 my $uri = '';
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 while (<$client>) {
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 $headers .= $_;
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 last if (/^\x0d?\x0a?$/);
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 next if $headers eq '';
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 print $client <<'EOF';
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 HTTP/1.1 101 Switching
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 Upgrade: foo
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 Connection: Upgrade
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 EOF
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 }
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120
ebaa2c72879d Tests: worker_shutdown_timeout on upgraded http connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 ###############################################################################