comparison t/gunzip-ssi.t @ 1:0dd7d109e56b

Gunzip: add more tests and improve docs.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 20 Dec 2009 03:55:31 +0300
parents
children 7170c171150c
comparison
equal deleted inserted replaced
0:a75d4ad9c5d2 1:0dd7d109e56b
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for gunzip filter module with subrequests.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13 use Test::Nginx qw/ :DEFAULT :gzip /;
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(4);
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
45 location / {
46 gunzip on;
47 gzip_vary on;
48 proxy_pass http://127.0.0.1:8081/;
49 proxy_set_header Accept-Encoding gzip;
50 }
51
52 location /t.html {
53 ssi on;
54 }
55 }
56
57 server {
58 listen 127.0.0.1:8081;
59 server_name localhost;
60
61 location / {
62 default_type text/plain;
63 gzip_static on;
64 gzip_http_version 1.0;
65 gzip_types text/plain;
66 }
67 }
68 }
69
70 EOF
71
72 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99));
73 my $out;
74
75 IO::Compress::Gzip::gzip(\$in => \$out);
76
77 $t->write_file('t1.gz', $out);
78 $t->write_file('t.html', 'xxx <!--#include virtual="/t1" --> xxx');
79
80 $t->run();
81
82 ###############################################################################
83
84 my $r = http_get('/t.html');
85 unlike($r, qr/Content-Encoding/, 'no content encoding');
86 like($r, qr/^xxx (X\d\d\dXXXXXX){100} xxx$/m, 'correct gunzipped response');
87
88 $r = http_gzip_request('/t.html');
89 unlike($r, qr/Content-Encoding/, 'gzip - no content encoding');
90 like($r, qr/(X\d\d\dXXXXXX){100}/m, 'gzip - correct gunzipped response');
91
92 ###############################################################################