annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for gunzip filter module with subrequests.
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13 use Test::Nginx qw/ :DEFAULT :gzip /;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15 ###############################################################################
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 select STDERR; $| = 1;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18 select STDOUT; $| = 1;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20 eval { require IO::Compress::Gzip; };
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23 my $t = Test::Nginx->new()->has('--with-http_gzip_static_module')->plan(4);
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 $t->write_file_expand('nginx.conf', <<'EOF');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 master_process off;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28 daemon off;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30 events {
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 }
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 http {
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 access_log off;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 root %%TESTDIR%%;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 client_body_temp_path %%TESTDIR%%/client_body_temp;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 proxy_temp_path %%TESTDIR%%/proxy_temp;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 server {
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 listen 127.0.0.1:8080;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 server_name localhost;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 location / {
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 gunzip on;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 gzip_vary on;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 proxy_pass http://127.0.0.1:8081/;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 proxy_set_header Accept-Encoding gzip;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 }
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 location /t.html {
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 ssi on;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 }
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 }
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 server {
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 listen 127.0.0.1:8081;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 server_name localhost;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 location / {
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 default_type text/plain;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 gzip_static on;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 gzip_http_version 1.0;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 gzip_types text/plain;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 }
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 }
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68 }
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 EOF
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99));
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 my $out;
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 IO::Compress::Gzip::gzip(\$in => \$out);
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 $t->write_file('t1.gz', $out);
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78 $t->write_file('t.html', 'xxx <!--#include virtual="/t1" --> xxx');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 $t->run();
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82 ###############################################################################
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84 my $r = http_get('/t.html');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85 unlike($r, qr/Content-Encoding/, 'no content encoding');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86 like($r, qr/^xxx (X\d\d\dXXXXXX){100} xxx$/m, 'correct gunzipped response');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 $r = http_gzip_request('/t.html');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 unlike($r, qr/Content-Encoding/, 'gzip - no content encoding');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90 like($r, qr/(X\d\d\dXXXXXX){100}/m, 'gzip - correct gunzipped response');
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91
0dd7d109e56b Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92 ###############################################################################