Mercurial > hg > nginx-tests
annotate proxy_cache_max_range_offset.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 766bcbb632ee |
children |
rev | line source |
---|---|
1078
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy cache, proxy_cache_max_range_offset directive. |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy cache/) |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 keys_zone=NAME:1m; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 proxy_pass http://127.0.0.1:8081/; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 proxy_cache NAME; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 proxy_cache_valid 200 1m; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 proxy_cache_max_range_offset 2; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 location /zero/ { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_pass http://127.0.0.1:8081/; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 proxy_cache NAME; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_cache_valid 200 1m; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 proxy_cache_max_range_offset 0; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /min_uses/ { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_pass http://127.0.0.1:8081/; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_cache NAME; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 proxy_cache_valid 200 1m; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_cache_max_range_offset 2; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 proxy_cache_min_uses 2; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 listen 127.0.0.1:8081; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 server_name localhost; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 location / { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 add_header X-Range $http_range; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 EOF |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 $t->write_file('t.html', 'SEE-THIS'); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1078
diff
changeset
|
81 $t->run()->plan(8); |
1078
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 ############################################################################### |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 unlike(get('/t.html?1', 'bytes=1-'), qr/X-Range/, 'range - below'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 like(get('/t.html?2', 'bytes=3-'), qr/X-Range/, 'range - above'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 like(get('/t.html?3', 'bytes=-1'), qr/X-Range/, 'range - last'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 TODO: { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 local $TODO = 'not yet'; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 like(get('/t.html?4', 'bytes=1-1,3-'), qr/X-Range/, 'range - multipart above'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 like(get('/zero/t.html?5', 'bytes=0-0'), qr/X-Range/, 'always non-cacheable'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 like(get('/min_uses/t.html?6', 'bytes=1-'), qr/X-Range/, 'below min_uses'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 # no range in client request |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 like(http_get('/t.html'), qr/SEE-THIS/, 'no range'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 $t->write_file('t.html', 'NOOP'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 like(http_get('/t.html'), qr/SEE-THIS/, 'no range - cached'); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 ############################################################################### |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 sub get { |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 my ($url, $extra) = @_; |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 return http(<<EOF); |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 GET $url HTTP/1.1 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 Host: localhost |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 Connection: close |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 Range: $extra |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 EOF |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 } |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
36437be7b3f4
Tests: proxy_cache_max_range_offset tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 ############################################################################### |