Mercurial > hg > nginx-tests
annotate proxy_force_ranges.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy cache and range filter. |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # proxy_force_ranges enables partial response regardless Accept-Ranges. |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
1474
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
16 use Socket qw/ $CRLF /; |
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
17 |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use lib 'lib'; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1474
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(7) |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 keys_zone=NAME:1m; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 proxy_pass http://127.0.0.1:8081; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
1211
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
52 location /proxy/ { |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
53 proxy_pass http://127.0.0.1:8081/; |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
54 proxy_force_ranges on; |
1474
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
55 add_trailer X-Trailer ""; |
1211
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
56 } |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
57 |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location /cache/ { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 proxy_pass http://127.0.0.1:8081/; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_cache NAME; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_cache_valid 200 1m; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_force_ranges on; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
68 listen 127.0.0.1:8081; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 server_name localhost; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 location / { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 max_ranges 0; |
1211
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
73 add_header Last-Modified "Mon, 28 Sep 1970 06:00:00 GMT"; |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
74 add_header ETag '"59a5401c-8"'; |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 EOF |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 $t->write_file('t.html', 'SEE-THIS'); |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
472
diff
changeset
|
82 $t->run(); |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 # serving range requests requires Accept-Ranges by default |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 unlike(http_get_range('/t.html', 'Range: bytes=4-'), qr/^THIS/m, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 'range without Accept-Ranges'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 like(http_get_range('/cache/t.html', 'Range: bytes=4-'), qr/^THIS/m, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 'uncached range'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 like(http_get_range('/cache/t.html', 'Range: bytes=4-'), qr/^THIS/m, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 'cached range'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 like(http_get_range('/cache/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms, |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 'cached multipart range'); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
1211
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
98 # If-Range HTTP-date request |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
99 |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
100 like(http_get_range('/proxy/t.html', |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
101 "Range: bytes=4-\nIf-Range: Mon, 28 Sep 1970 06:00:00 GMT"), |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
102 qr/^THIS/m, 'if-range last-modified proxy'); |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
103 |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
104 # If-Range entity-tag request |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
105 |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
106 like(http_get_range('/proxy/t.html', |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
107 "Range: bytes=4-\nIf-Range: \"59a5401c-8\""), |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
108 qr/^THIS/m, 'if-range etag proxy'); |
0c15ba7d19b3
Tests: If-Range tests with proxy.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
109 |
1474
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
110 # range sent using chunked transfer encoding |
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
111 |
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
112 like(http_get_range('/proxy/t.html', 'Range: bytes=-2'), |
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
113 qr/2${CRLF}IS${CRLF}0$CRLF$CRLF$/, 'no dublicate final chunk'); |
f026c41335b2
Tests: range filter and chunked transfer encoding test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
114 |
472
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 ############################################################################### |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 sub http_get_range { |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 my ($url, $extra) = @_; |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 return http(<<EOF); |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 GET $url HTTP/1.1 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 Host: localhost |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 Connection: close |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 $extra |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 EOF |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 } |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 |
c8e790dcbe19
Tests: proxy_force_ranges tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 ############################################################################### |