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