comparison ssi-include-big.t @ 95:cbc17561ef4d

Merge.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 08 Jun 2009 23:06:18 +0400
parents 5276d85d5040
children 8bc9de6559a1
comparison
equal deleted inserted replaced
94:9ab3762332b9 95:cbc17561ef4d
12 use Test::More; 12 use Test::More;
13 13
14 BEGIN { use FindBin; chdir($FindBin::Bin); } 14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15 15
16 use lib 'lib'; 16 use lib 'lib';
17 use Test::Nginx; 17 use Test::Nginx qw/ :DEFAULT :gzip /;
18 18
19 ############################################################################### 19 ###############################################################################
20 20
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
88 88
89 my $t4 = http_gzip_request('/test4.html'); 89 my $t4 = http_gzip_request('/test4.html');
90 ok(defined $t4, 'big ssi main file'); 90 ok(defined $t4, 'big ssi main file');
91 http_gzip_like($t4, qr/^X{1025}\Z/, 'big ssi main file content'); 91 http_gzip_like($t4, qr/^X{1025}\Z/, 'big ssi main file content');
92 92
93
94 ############################################################################### 93 ###############################################################################
95
96 sub http_gzip_request {
97 my ($url) = @_;
98 my $r = http(<<EOF);
99 GET $url HTTP/1.1
100 Host: localhost
101 Connection: close
102 Accept-Encoding: gzip
103
104 EOF
105 }
106
107 sub http_content {
108 my ($text) = @_;
109
110 return undef if !defined $text;
111
112 if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) {
113 return undef;
114 }
115
116 my ($headers, $body) = ($1, $2);
117
118 if ($headers !~ /Transfer-Encoding: chunked/i) {
119 return $body;
120 }
121
122 my $content = '';
123 while ($body =~ /\G\x0d?\x0a?([0-9a-f]+)\x0d\x0a?/gcmsi) {
124 my $len = hex($1);
125 $content .= substr($body, pos($body), $len);
126 pos($body) += $len;
127 }
128
129 return $content;
130 }
131
132 sub http_gzip_like {
133 my ($text, $re, $name) = @_;
134
135 SKIP: {
136 eval { require IO::Uncompress::Gunzip; };
137 skip "IO::Uncompress::Gunzip not installed", 1 if $@;
138
139 my $in = http_content($text);
140 my $out;
141
142 IO::Uncompress::Gunzip::gunzip(\$in => \$out);
143
144 like($out, $re, $name);
145 }
146 }
147
148 ###############################################################################