annotate http_location_auto.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
330
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for location selection, an auto_redirect edge case.
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4)
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 daemon off;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 events {
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 http {
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
38 listen 127.0.0.1:8080;
330
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 server_name localhost;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 proxy_hide_header X-Location;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 add_header X-Location unset;
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 # As of nginx 1.5.4, this results in the following
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 # location tree:
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 #
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 # "/a-b"
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 # "/a-a" "/a/"
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 #
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 # A request to "/a" is expected to match "/a/" with auto_redirect,
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 # but with such a tree it tests locations "/a-b", "/a-a" and then
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 # falls back to null location.
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 #
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 # Key factor is that "-" is less than "/".
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
56 location /a/ { proxy_pass http://127.0.0.1:8080/a-a; }
330
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 location /a-a { add_header X-Location a-a; return 204; }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 location /a-b { add_header X-Location a-b; return 204; }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 }
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 EOF
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 $t->run();
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 ###############################################################################
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 like(http_get('/a'), qr/301 Moved/, 'auto redirect');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 like(http_get('/a/'), qr/X-Location: unset/, 'match a');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 like(http_get('/a-a'), qr/X-Location: a-a/, 'match a-a');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 like(http_get('/a-b'), qr/X-Location: a-b/, 'match a-b');
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
617f72beba8d Tests: location auto_redirect edge case test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 ###############################################################################