Mercurial > hg > nginx-tests
changeset 95:cbc17561ef4d
Merge.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 08 Jun 2009 23:06:18 +0400 |
parents | 9ab3762332b9 (current diff) 5276d85d5040 (diff) |
children | ecff5407867c |
files | |
diffstat | 4 files changed, 174 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gzip.t Mon Jun 08 23:06:18 2009 +0400 @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +# (C) Maxim Dounin + +# Tests for nginx gzip filter module. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx qw/ :DEFAULT :gzip /; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +my $t = Test::Nginx->new()->plan(6); + +$t->write_file_expand('nginx.conf', <<'EOF'); + +master_process off; +daemon off; + +events { +} + +http { + access_log off; + root %%TESTDIR%%; + + client_body_temp_path %%TESTDIR%%/client_body_temp; + fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; + proxy_temp_path %%TESTDIR%%/proxy_temp; + + server { + listen 127.0.0.1:8080; + server_name localhost; + location / { + gzip on; + } + location /proxy/ { + gzip on; + proxy_pass http://127.0.0.1:8080/local/; + } + location /local/ { + gzip off; + alias %%TESTDIR%%/; + } + } +} + +EOF + +$t->write_file('index.html', 'X' x 64); + +$t->run(); + +############################################################################### + +my $r; + +$r = http_gzip_request('/'); +like($r, qr/^Content-Encoding: gzip/m, 'gzip'); +http_gzip_like($r, qr/^X{64}\Z/, 'gzip content correct'); + +$r = http_gzip_request('/proxy/'); +like($r, qr/^Content-Encoding: gzip/m, 'gzip proxied'); +http_gzip_like($r, qr/^X{64}\Z/, 'gzip proxied content'); + +# Accept-Ranges headers should be cleared + +unlike(http_gzip_request('/'), qr/Accept-Ranges/im, 'cleared accept-ranges'); + +TODO: { +local $TODO = 'broken since 0.7.44'; + +unlike(http_gzip_request('/proxy/'), qr/Accept-Ranges/im, + 'cleared headers from proxy'); + +} + +###############################################################################
--- a/lib/Test/Nginx.pm Sun May 10 03:53:20 2009 +0400 +++ b/lib/Test/Nginx.pm Mon Jun 08 23:06:18 2009 +0400 @@ -12,6 +12,10 @@ use base qw/ Exporter /; our @EXPORT = qw/ log_in log_out http http_get http_head /; +our @EXPORT_OK = qw/ http_gzip_request http_gzip_like /; +our %EXPORT_TAGS = ( + gzip => [ qw/ http_gzip_request http_gzip_like / ] +); ############################################################################### @@ -275,6 +279,61 @@ ############################################################################### +sub http_gzip_request { + my ($url) = @_; + my $r = http(<<EOF); +GET $url HTTP/1.1 +Host: localhost +Connection: close +Accept-Encoding: gzip + +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; }; + Test::More->builder->skip( + "IO::Uncompress::Gunzip not installed", 1) if $@; + + my $in = http_content($text); + my $out; + + IO::Uncompress::Gunzip::gunzip(\$in => \$out); + + Test::More->builder->like($out, $re, $name); + } +} + +############################################################################### + 1; ###############################################################################
--- a/ssi-include-big.t Sun May 10 03:53:20 2009 +0400 +++ b/ssi-include-big.t Mon Jun 08 23:06:18 2009 +0400 @@ -14,7 +14,7 @@ BEGIN { use FindBin; chdir($FindBin::Bin); } use lib 'lib'; -use Test::Nginx; +use Test::Nginx qw/ :DEFAULT :gzip /; ############################################################################### @@ -90,59 +90,4 @@ ok(defined $t4, 'big ssi main file'); http_gzip_like($t4, qr/^X{1025}\Z/, 'big ssi main file content'); - ############################################################################### - -sub http_gzip_request { - my ($url) = @_; - my $r = http(<<EOF); -GET $url HTTP/1.1 -Host: localhost -Connection: close -Accept-Encoding: gzip - -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); - } -} - -###############################################################################
--- a/ssi.t Sun May 10 03:53:20 2009 +0400 +++ b/ssi.t Mon Jun 08 23:06:18 2009 +0400 @@ -21,7 +21,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->plan(9); +my $t = Test::Nginx->new()->plan(11); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -42,7 +42,17 @@ server { listen 127.0.0.1:8080; server_name localhost; - ssi on; + location / { + ssi on; + } + location /proxy/ { + ssi on; + proxy_pass http://127.0.0.1:8080/local/; + } + location /local/ { + ssi off; + alias %%TESTDIR%%/; + } } } @@ -71,4 +81,17 @@ like(http_get('/test3.html'), qr/^XtestX$/m, 'set'); +# Last-Modified and Accept-Ranges headers should be cleared + +unlike(http_get('/test1.html'), qr/Last-Modified|Accept-Ranges/im, + 'cleared headers'); + +TODO: { +local $TODO = 'broken since 0.7.44'; + +unlike(http_get('/proxy/test1.html'), qr/Last-Modified|Accept-Ranges/im, + 'cleared headers from proxy'); + +} + ###############################################################################