399
|
1 #!/usr/bin/perl
|
|
2
|
|
3 # (C) Maxim Dounin
|
|
4 # (C) Nginx, Inc.
|
|
5
|
|
6 # Tests for charset filter.
|
|
7
|
|
8 ###############################################################################
|
|
9
|
|
10 use warnings;
|
|
11 use strict;
|
|
12
|
|
13 use Test::More;
|
|
14
|
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
|
|
16
|
|
17 use lib 'lib';
|
|
18 use Test::Nginx qw/ :DEFAULT :gzip /;
|
|
19
|
|
20 ###############################################################################
|
|
21
|
|
22 select STDERR; $| = 1;
|
|
23 select STDOUT; $| = 1;
|
|
24
|
|
25 my $t = Test::Nginx->new()->has(qw/http charset gzip_static/)->plan(13)
|
|
26 ->write_file_expand('nginx.conf', <<'EOF')->run();
|
|
27
|
|
28 %%TEST_GLOBALS%%
|
|
29
|
|
30 daemon off;
|
|
31
|
|
32 events {
|
|
33 }
|
|
34
|
|
35 http {
|
|
36 %%TEST_GLOBALS_HTTP%%
|
|
37
|
|
38 types {
|
|
39 text/html html;
|
|
40 }
|
|
41
|
|
42 charset_map B A {
|
|
43 58 59; # X -> Y
|
|
44 }
|
|
45
|
|
46 server {
|
|
47 listen 127.0.0.1:8080;
|
|
48 server_name localhost;
|
|
49
|
|
50 location /t1 {
|
|
51 charset utf-8;
|
|
52 gzip_static on;
|
|
53 }
|
|
54
|
|
55 location /t2 {
|
|
56 gzip_static on;
|
|
57 charset A;
|
|
58 source_charset B;
|
|
59 }
|
|
60
|
|
61 location /t {
|
|
62 gzip_static on;
|
|
63 }
|
|
64
|
|
65 location /p/ {
|
|
66 charset utf-8;
|
|
67 proxy_pass http://127.0.0.1:8080/;
|
|
68 proxy_http_version 1.1;
|
|
69 }
|
|
70
|
|
71 location /p.ab/ {
|
|
72 charset A;
|
|
73 source_charset B;
|
|
74 proxy_pass http://127.0.0.1:8080/;
|
|
75 proxy_http_version 1.1;
|
|
76 }
|
|
77
|
|
78 location /p.aa/ {
|
|
79 charset A;
|
|
80 source_charset A;
|
|
81 proxy_pass http://127.0.0.1:8080/;
|
|
82 proxy_http_version 1.1;
|
|
83 }
|
|
84 }
|
|
85 }
|
|
86
|
|
87 EOF
|
|
88
|
|
89 $t->write_file('t1.html', '');
|
|
90 $t->write_file('t1.html.gz', '');
|
|
91
|
|
92 my $in = 'X' x 99;
|
|
93 my $out;
|
|
94
|
|
95 eval {
|
|
96 require IO::Compress::Gzip;
|
|
97 IO::Compress::Gzip::gzip(\$in => \$out);
|
|
98 };
|
|
99
|
|
100 $t->write_file('t2.html', $in);
|
|
101 $t->write_file('t2.html.gz', $out);
|
|
102
|
|
103 $t->write_file('t.html', '');
|
|
104 $t->write_file('t.html.gz', '');
|
|
105
|
|
106 ###############################################################################
|
|
107
|
|
108 # charset filter currently ignores responses with Content-Encoding set
|
|
109 # (except ones with r->ignore_content_encoding used by gzip_static)
|
|
110 # as it can't convert such content; there are two problems though:
|
|
111 #
|
|
112 # - it make sense to indicate charset
|
|
113 # if conversion isn't needed
|
|
114 #
|
|
115 # - gzip_static may need conversion, too
|
|
116 #
|
|
117 # proper solution seems to be to always allow charset indication, but
|
|
118 # don't try to do anything if recoding is needed
|
|
119
|
|
120 like(http_get('/t1.html'), qr!text/html; charset=!, 'plain');
|
|
121 like(http_gzip_request('/t1.html'), qr!text/html; charset=.*gzip!ms, 'gzip');
|
|
122
|
|
123 like(http_get('/t2.html'), qr!text/html; charset=A.*Y{99}!ms, 'recode plain');
|
|
124
|
|
125 TODO: {
|
|
126 local $TODO = 'not yet';
|
|
127
|
|
128 like(http_gzip_request('/t2.html'), qr!text/html\x0d.*gzip!ms, 'recode gzip');
|
|
129 http_gzip_like(http_gzip_request('/t2.html'), qr!X{99}!, 'recode content');
|
|
130
|
|
131 }
|
|
132
|
|
133 like(http_get('/t.html'), qr!text/html\x0d!, 'nocharset plain');
|
|
134 like(http_gzip_request('/t.html'), qr!text/html\x0d.*gzip!ms, 'nocharset gzip');
|
|
135
|
|
136 like(http_get('/p/t.html'), qr!text/html; charset=!, 'proxy plain');
|
|
137
|
|
138 TODO: {
|
|
139 local $TODO = 'not yet';
|
|
140
|
|
141 like(http_gzip_request('/p/t.html'), qr!text/html; charset=.*gzip!ms,
|
|
142 'proxy gzip');
|
|
143
|
|
144 }
|
|
145
|
|
146
|
|
147 like(http_get('/p.ab/t.html'), qr!text/html; charset=A!ms,
|
|
148 'proxy recode plain');
|
|
149
|
|
150 TODO: {
|
|
151 local $TODO = 'not yet';
|
|
152
|
|
153 like(http_gzip_request('/p.ab/t.html'), qr!text/html\x0d; charset=.*gzip!ms,
|
|
154 'proxy recode gzip');
|
|
155
|
|
156 }
|
|
157
|
|
158 like(http_get('/p.aa/gz.html'), qr!text/html; charset=A!ms,
|
|
159 'proxy nullrecode plain');
|
|
160
|
|
161 TODO: {
|
|
162 local $TODO = 'not yet';
|
|
163
|
|
164 like(http_gzip_request('/p.aa/gz.html'), qr!text/html\x0d; charset=.*gzip!ms,
|
|
165 'proxy nullrecode gzip');
|
|
166
|
|
167 }
|
|
168
|
|
169 ###############################################################################
|