Tests: check content returned from ssi tests.
Since replies are gzipped, IO::Uncompress::Gunzip required for this (if not
installed tests are skipped).
This should catch truncated replies as fixed in nginx 0.7.4.
diff --git a/ssi-include-big.t b/ssi-include-big.t
index 6794b25..50f8066 100644
--- a/ssi-include-big.t
+++ b/ssi-include-big.t
@@ -21,7 +21,7 @@
select STDERR; $| = 1;
select STDOUT; $| = 1;
-my $t = Test::Nginx->new()->has('rewrite')->plan(3);
+my $t = Test::Nginx->new()->has('rewrite')->plan(8);
$t->write_file_expand('nginx.conf', <<'EOF');
@@ -62,12 +62,14 @@
$t->write_file('c1.html', 'X' x 1023);
$t->write_file('c2.html', 'X' x 1024);
$t->write_file('c3.html', 'X' x 1025);
-$t->write_file('test1.html', '<!--#include virtual="/proxy/blah" -->' . "\n"
+$t->write_file('test1.html', '<!--#include virtual="/proxy/blah" -->'
. '<!--#include virtual="/c1.html" -->');
-$t->write_file('test2.html', '<!--#include virtual="/proxy/blah" -->' . "\n"
+$t->write_file('test2.html', '<!--#include virtual="/proxy/blah" -->'
. '<!--#include virtual="/c2.html" -->');
-$t->write_file('test3.html', '<!--#include virtual="/proxy/blah" -->' . "\n"
+$t->write_file('test3.html', '<!--#include virtual="/proxy/blah" -->'
. '<!--#include virtual="/c3.html" -->');
+$t->write_file('test4.html', '<!--#include virtual="/proxy/blah" -->'
+ . ('X' x 1025));
$t->run();
@@ -75,18 +77,26 @@
my $t1 = http_gzip_request('/test1.html');
ok(defined $t1, 'small included file (less than output_buffers)');
+http_gzip_like($t1, qr/^X{1023}\Z/, 'small included file content');
my $t2 = http_gzip_request('/test2.html');
ok(defined $t2, 'small included file (equal to output_buffers)');
+http_gzip_like($t2, qr/^X{1024}\Z/, 'small included file content');
TODO: {
local $TODO = 'not fixed yet, patch under review';
my $t3 = http_gzip_request('/test3.html');
ok(defined $t3, 'big included file (more than output_buffers)');
+http_gzip_like($t3, qr/^X{1025}\Z/, 'big included file content');
}
+my $t4 = http_gzip_request('/test4.html');
+ok(defined $t4, 'big ssi main file');
+http_gzip_like($t4, qr/^X{1025}\Z/, 'big ssi main file content');
+
+
###############################################################################
sub http_gzip_request {
@@ -100,4 +110,45 @@
EOF
}
+sub http_content {
+ my ($text) = @_;
+
+ return undef if !defined $text;
+
+ if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) {
+ return undef;
+ }
+
+ my ($headers, $body) = ($1, $2);
+
+ if ($headers !~ /Transfer-Encoding: chunked/i) {
+ return $body;
+ }
+
+ my $content = '';
+ while ($body =~ /\G\x0d?\x0a?([0-9a-f]+)\x0d\x0a?/gcmsi) {
+ my $len = hex($1);
+ $content .= substr($body, pos($body), $len);
+ pos($body) += $len;
+ }
+
+ return $content;
+}
+
+sub http_gzip_like {
+ my ($text, $re, $name) = @_;
+
+ SKIP: {
+ eval { require IO::Uncompress::Gunzip; };
+ skip "IO::Uncompress::Gunzip not installed", 1 if $@;
+
+ my $in = http_content($text);
+ my $out;
+
+ IO::Uncompress::Gunzip::gunzip(\$in => \$out);
+
+ like($out, $re, $name);
+ }
+}
+
###############################################################################