comparison t/gunzip-static.t @ 4:2698bf018167

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