Mercurial > hg > ngx_http_gunzip_filter_module
comparison t/gunzip.t @ 0:a75d4ad9c5d2
Gunzip filter module.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 13 Dec 2009 00:24:03 +0300 |
parents | |
children | 0dd7d109e56b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a75d4ad9c5d2 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for gunzip filter module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 use Test::Nginx; | |
14 | |
15 ############################################################################### | |
16 | |
17 select STDERR; $| = 1; | |
18 select STDOUT; $| = 1; | |
19 | |
20 eval { require IO::Compress::Gzip; }; | |
21 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@; | |
22 | |
23 my $t = Test::Nginx->new()->has('--with-http_gzip_static_module')->plan(10); | |
24 | |
25 $t->write_file_expand('nginx.conf', <<'EOF'); | |
26 | |
27 master_process off; | |
28 daemon off; | |
29 | |
30 events { | |
31 } | |
32 | |
33 http { | |
34 access_log off; | |
35 root %%TESTDIR%%; | |
36 | |
37 client_body_temp_path %%TESTDIR%%/client_body_temp; | |
38 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; | |
39 proxy_temp_path %%TESTDIR%%/proxy_temp; | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080; | |
43 server_name localhost; | |
44 location / { | |
45 gunzip on; | |
46 gzip_vary on; | |
47 proxy_pass http://127.0.0.1:8081/; | |
48 proxy_set_header Accept-Encoding gzip; | |
49 } | |
50 location /error { | |
51 error_page 500 /t1; | |
52 return 500; | |
53 } | |
54 } | |
55 | |
56 server { | |
57 listen 127.0.0.1:8081; | |
58 server_name localhost; | |
59 | |
60 location / { | |
61 default_type text/plain; | |
62 gzip_static on; | |
63 gzip_http_version 1.0; | |
64 gzip_types text/plain; | |
65 } | |
66 } | |
67 } | |
68 | |
69 EOF | |
70 | |
71 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)); | |
72 my $out; | |
73 | |
74 IO::Compress::Gzip::gzip(\$in => \$out); | |
75 | |
76 $t->write_file('t1.gz', $out); | |
77 $t->write_file('t2.gz', $out . $out); | |
78 $t->write_file('t3', 'not compressed'); | |
79 | |
80 $t->run(); | |
81 | |
82 ############################################################################### | |
83 | |
84 pass('runs'); | |
85 | |
86 my $t1 = http_get('/t1'); | |
87 unlike($t1, qr/Content-Encoding/, 'no content encoding'); | |
88 like($t1, qr/^(X\d\d\dXXXXXX){100}$/m, 'correct ungzipped response'); | |
89 | |
90 like(http_get('/t2'), qr/^(X\d\d\dXXXXXX){200}$/m, 'multiple gzip members'); | |
91 | |
92 like(http_get('/error'), qr/^(X\d\d\dXXXXXX){100}$/m, 'errors ungzipped'); | |
93 | |
94 unlike(http_head('/t1'), qr/Content-Encoding/, 'head - no content encoding'); | |
95 | |
96 like(http_get('/t1'), qr/Vary/, 'get vary'); | |
97 like(http_head('/t1'), qr/Vary/, 'head vary'); | |
98 unlike(http_get('/t3'), qr/Vary/, 'no vary on non-gzipped get'); | |
99 unlike(http_head('/t3'), qr/Vary/, 'no vary on non-gzipped head'); | |
100 | |
101 ############################################################################### |