Mercurial > hg > nginx-tests
annotate charset_gzip_static.t @ 431:05c46688b54b
Tests: ssl_password_file.t fixes.
Make sure to always specify listen socket in all servers as the
default vary (under root, nginx will try to listen on 80). Make sure
to detect if an https request was processed by http.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 09 Jul 2014 05:19:51 +0400 |
parents | a8bfad2a3f84 |
children | 907e89fba9c3 |
rev | line source |
---|---|
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 { | |
405
a8bfad2a3f84
Tests: whitespace fix.
Sergey Kandaurov <pluknet@nginx.com>
parents:
403
diff
changeset
|
96 require IO::Compress::Gzip; |
399 | 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: { | |
403
22f6aa0d1139
Tests: added version checks to charset_gzip_static.t TODOs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
402
diff
changeset
|
126 local $TODO = 'not yet' unless $t->has_version('1.7.1'); |
399 | 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: { | |
403
22f6aa0d1139
Tests: added version checks to charset_gzip_static.t TODOs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
402
diff
changeset
|
139 local $TODO = 'not yet' unless $t->has_version('1.7.1'); |
399 | 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'); | |
401
2961a6a83809
Tests: fixed charset_gzip_static.t tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
399
diff
changeset
|
149 like(http_gzip_request('/p.ab/t.html'), qr!text/html\x0d.*gzip!ms, |
399 | 150 'proxy recode gzip'); |
151 | |
401
2961a6a83809
Tests: fixed charset_gzip_static.t tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
399
diff
changeset
|
152 like(http_get('/p.aa/t.html'), qr!text/html; charset=A!ms, |
399 | 153 'proxy nullrecode plain'); |
154 | |
155 TODO: { | |
403
22f6aa0d1139
Tests: added version checks to charset_gzip_static.t TODOs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
402
diff
changeset
|
156 local $TODO = 'not yet' unless $t->has_version('1.7.1'); |
399 | 157 |
401
2961a6a83809
Tests: fixed charset_gzip_static.t tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
399
diff
changeset
|
158 like(http_gzip_request('/p.aa/t.html'), qr!text/html; charset=A.*gzip!ms, |
399 | 159 'proxy nullrecode gzip'); |
160 | |
161 } | |
162 | |
163 ############################################################################### |