annotate proxy_cache_path.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 196d33c2bb45
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
521
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for http proxy cache with use_temp_path parameter.
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1020
196d33c2bb45 Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 974
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(6)
521
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 proxy_cache_path %%TESTDIR%%/cache1
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 keys_zone=ON:1m use_temp_path=on;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 proxy_cache_path %%TESTDIR%%/cache2
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 keys_zone=OFF:1m use_temp_path=off;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 proxy_cache_path %%TESTDIR%%/cache4 levels=1:2
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 keys_zone=LEVELS:1m use_temp_path=off;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
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;
521
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 server_name localhost;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 location / {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
50 proxy_pass http://127.0.0.1:8081;
521
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 proxy_cache $arg_c;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 proxy_cache_valid any 1m;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 add_header X-Cache-Status $upstream_cache_status;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 }
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
61 listen 127.0.0.1:8081;
521
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 server_name localhost;
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 location / {
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 }
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 }
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 }
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 EOF
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 $t->write_file('t', 'SEE-THIS');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
568
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 522
diff changeset
73 $t->run();
521
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 ###############################################################################
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 like(http_get('/t?c=ON'), qr/MISS.*SEE-THIS/ms, 'temp path');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 like(http_get('/t?c=OFF'), qr/MISS.*SEE-THIS/ms, 'temp path off');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 like(http_get('/t?c=LEVELS'), qr/MISS.*SEE-THIS/ms, 'temp path levels');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 $t->write_file('t', 'SEE-THAT');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 like(http_get('/t?c=ON'), qr/HIT.*SEE-THIS/ms, 'temp path cached');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 like(http_get('/t?c=OFF'), qr/HIT.*SEE-THIS/ms, 'temp path cached off');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 like(http_get('/t?c=LEVELS'), qr/HIT.*SEE-THIS/ms, 'temp path cached levels');
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86
6b9bfe18fdc8 Tests: proxy_cache_path with use_temp_path parameter.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 ###############################################################################