Mercurial > hg > nginx-tests
comparison gunzip_ssi.t @ 231:bc1861122d0c
Tests: gunzip filter tests import.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 07 Sep 2012 20:30:32 +0400 |
parents | |
children | 6a0d934950bc |
comparison
equal
deleted
inserted
replaced
230:9d7805b05f0f | 231:bc1861122d0c |
---|---|
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 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx qw/ :DEFAULT :gzip /; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 eval { require IO::Compress::Gzip; }; | |
25 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@; | |
26 | |
27 my $t = Test::Nginx->new()->has(qw/http gunzip ssi proxy gzip_static/) | |
28 ->plan(4); | |
29 | |
30 $t->write_file_expand('nginx.conf', <<'EOF'); | |
31 | |
32 %%TEST_GLOBALS%% | |
33 | |
34 daemon off; | |
35 | |
36 events { | |
37 } | |
38 | |
39 http { | |
40 %%TEST_GLOBALS_HTTP%% | |
41 | |
42 server { | |
43 listen 127.0.0.1:8080; | |
44 server_name localhost; | |
45 | |
46 location / { | |
47 gunzip on; | |
48 gzip_vary on; | |
49 proxy_pass http://127.0.0.1:8081/; | |
50 proxy_set_header Accept-Encoding gzip; | |
51 } | |
52 | |
53 location /t.html { | |
54 ssi on; | |
55 } | |
56 } | |
57 | |
58 server { | |
59 listen 127.0.0.1:8081; | |
60 server_name localhost; | |
61 | |
62 location / { | |
63 default_type text/plain; | |
64 gzip_static on; | |
65 gzip_http_version 1.0; | |
66 gzip_types text/plain; | |
67 } | |
68 } | |
69 } | |
70 | |
71 EOF | |
72 | |
73 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)); | |
74 my $out; | |
75 | |
76 IO::Compress::Gzip::gzip(\$in => \$out); | |
77 | |
78 $t->write_file('t1.gz', $out); | |
79 $t->write_file('t.html', 'xxx <!--#include virtual="/t1" --> xxx'); | |
80 | |
81 $t->run(); | |
82 | |
83 ############################################################################### | |
84 | |
85 my $r = http_get('/t.html'); | |
86 unlike($r, qr/Content-Encoding/, 'no content encoding'); | |
87 like($r, qr/^xxx (X\d\d\dXXXXXX){100} xxx$/m, 'correct gunzipped response'); | |
88 | |
89 $r = http_gzip_request('/t.html'); | |
90 unlike($r, qr/Content-Encoding/, 'gzip - no content encoding'); | |
91 like($r, qr/(X\d\d\dXXXXXX){100}/m, 'gzip - correct gunzipped response'); | |
92 | |
93 ############################################################################### |