Mercurial > hg > nginx-tests
annotate range_charset.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 196d33c2bb45 |
children |
rev | line source |
---|---|
373
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for range filter on proxied response with charset. |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
1e6e216b06c2
Tests: range filter tests with charset.
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 charset/)->plan(10) |
373
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 charset_map B A { |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 58 59; # X -> Y |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 keys_zone=NAME:1m; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
1e6e216b06c2
Tests: range filter tests with charset.
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; |
373
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 server_name localhost; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
1e6e216b06c2
Tests: range filter tests with charset.
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; |
373
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 proxy_cache NAME; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 proxy_cache_valid 200 1m; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 listen 127.0.0.1:8081; |
373
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server_name localhost; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 charset B; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location /t2.html { |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 add_header X-Accel-Charset A; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 EOF |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 $t->write_file('t1.html', |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 $t->write_file('t2.html', |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $t->run(); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 ############################################################################### |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 my $t1; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 # range request on proxied response with charset attribute in content-type |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 # NB: to get partial content, requests need to be served from cache |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 http_get('/t1.html'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, 10-19'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
85 like($t1, qr/ 206 /, 'charset - 206 partial reply'); |
373
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 like($t1, qr/Content-Type: multipart\/byteranges; boundary=\w+\x0d\x0a/, |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 'charset - content type'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like($t1, qr/Content-Type: text\/html; charset=B(?!; charset)/, |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 'charset - charset attribute'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 like($t1, qr/X000XXXXXX/m, 'charset - content 0-9'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 like($t1, qr/X001XXXXXX\x0d?$/m, 'charset - content 10-19'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 http_get('/t2.html'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 $t1 = http_get_range('/t2.html', 'Range: bytes=0-9, 10-19'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
95 like($t1, qr/ 206 /, 'x-accel-charset - 206 partial reply'); |
373
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 like($t1, qr/Content-Type: multipart\/byteranges; boundary=\w+\x0d\x0a/, |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 'x-accel-charset - content type'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 like($t1, qr/Content-Type: text\/html; charset=A(?!; charset)/, |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 'x-accel-charset - charset attribute'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 like($t1, qr/Y000YYYYYY/m, 'x-accel-charset - content 0-9'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 like($t1, qr/Y001YYYYYY\x0d?$/m, 'x-accel-charset - content 10-19'); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 ############################################################################### |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 sub http_get_range { |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 my ($url, $extra) = @_; |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 return http(<<EOF); |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 GET $url HTTP/1.1 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 Host: localhost |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 Connection: close |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 $extra |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 EOF |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 } |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
1e6e216b06c2
Tests: range filter tests with charset.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 ############################################################################### |