annotate split_clients.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 882267679006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
348
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for split_client module.
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http split_clients/)->plan(1);
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 split_clients $connection $variant {
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 51.2% ".one";
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 10% ".two";
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 * ".three";
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
46 listen 127.0.0.1:8080;
348
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 server_name localhost;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 location / {
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 index index${variant}.html;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 EOF
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 $t->write_file('index.one.html', 'first');
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 $t->write_file('index.two.html', 'second');
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 $t->write_file('index.three.html', 'third');
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 $t->run();
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 ###############################################################################
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 # NB: split_clients distribution is a subject to implementation details
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 like(many('/', 20), qr/first: 12, second: 2, third: 6/, 'split');
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 ###############################################################################
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 sub many {
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 my ($uri, $count) = @_;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 my %dist;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 for (1 .. $count) {
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 if (http_get($uri) =~ /(first|second|third)/) {
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 $dist{$1} = 0 unless defined $dist{$1};
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 $dist{$1}++;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 return join ', ', map { $_ . ": " . $dist{$_} } sort keys %dist;
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 }
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 ###############################################################################