# HG changeset patch # User Maxim Dounin # Date 1223936283 -14400 # Node ID 4f57d57543e178eefed6833fe5414f66eac321f8 # Parent 18296293d18af1a46cff5e08d16417e925a7a2aa Tests: range filter tests. diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -48,8 +48,8 @@ sub has { my %regex = ( mail => '--with-mail', + flv => '--with-http_flv_module', rewrite => '(?s)^(?!.*--without-http_rewrite_module)', - static => '(?s)^(?!.*--without-http_static_module)', ); Test::More::plan(skip_all => "$feature not compiled in") diff --git a/range-flv.t b/range-flv.t new file mode 100644 --- /dev/null +++ b/range-flv.t @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +# (C) Maxim Dounin + +# Tests for range filter module. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +my $t = Test::Nginx->new()->has('flv')->plan(12); + +$t->write_file_expand('nginx.conf', <<'EOF'); + +master_process off; +daemon off; + +events { + worker_connections 1024; +} + +http { + access_log off; + root %%TESTDIR%%; + + server { + listen localhost:8080; + server_name localhost; + location / { + flv; + } + } +} + +EOF + +$t->write_file('t1.flv', + join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); +$t->run(); + +############################################################################### + +my $t1; + +# FLV has 13 byte header at start. + +$t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=0-9'); +like($t1, qr/206/, 'first bytes - 206 partial reply'); +like($t1, qr/Content-Length: 10/, 'first bytes - correct length'); +like($t1, qr/Content-Range: bytes 0-9\/913/, 'first bytes - content range'); +like($t1, qr/^FLV.{7}$/m, 'first bytes - correct content'); + +$t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=-10'); +like($t1, qr/206/, 'final bytes - 206 partial reply'); +like($t1, qr/Content-Length: 10/, 'final bytes - content length'); +like($t1, qr/Content-Range: bytes 903-912\/913/, + 'final bytes - content range'); +like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); + +$t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=0-99'); +like($t1, qr/206/, 'multi buffers - 206 partial reply'); +like($t1, qr/Content-Length: 100/, 'multi buffers - content length'); +like($t1, qr/Content-Range: bytes 0-99\/913/, 'multi buffers - content range'); +like($t1, qr/^FLV.{10}X010XXXXXX(X01[1-7]XXXXXX){7}X018XXX$/m, + 'multi buffers - correct content'); + +############################################################################### + +sub http_get_range { + my ($url, $extra) = @_; + return http(<new()->plan(25); + +$t->write_file_expand('nginx.conf', <<'EOF'); + +master_process off; +daemon off; + +events { + worker_connections 1024; +} + +http { + access_log off; + root %%TESTDIR%%; + + charset_map B A { + 58 59; # X -> Y + } + + server { + listen localhost:8080; + server_name localhost; + + location /t2.html { + charset A; + source_charset B; + } + } +} + +EOF + +$t->write_file('t1.html', + join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); +$t->write_file('t2.html', + join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); +$t->run(); + +############################################################################### + +my $t1; + +$t1 = http_get_range('/t1.html', 'Range: bytes=0-8'); +like($t1, qr/206/, 'range request - 206 partial reply'); +like($t1, qr/Content-Length: 9/, 'range request - correct length'); +like($t1, qr/Content-Range: bytes 0-8\/1000/, 'range request - content range'); +like($t1, qr/^X000XXXXX$/m, 'range request - correct content'); + +$t1 = http_get_range('/t1.html', 'Range: bytes=-10'); +like($t1, qr/206/, 'final bytes - 206 partial reply'); +like($t1, qr/Content-Length: 10/, 'final bytes - content length'); +like($t1, qr/Content-Range: bytes 990-999\/1000/, + 'final bytes - content range'); +like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); + +$t1 = http_get_range('/t1.html', 'Range: bytes=990-'); +like($t1, qr/206/, 'final bytes explicit - 206 partial reply'); +like($t1, qr/Content-Length: 10/, 'final bytes explicit - content length'); +like($t1, qr/Content-Range: bytes 990-999\/1000/, + 'final bytes explicit - content range'); +like($t1, qr/^X099XXXXXX$/m, 'final bytes explicit - correct content'); + +$t1 = http_get_range('/t1.html', 'Range: bytes=990-1990'); +like($t1, qr/206/, 'more than length - 206 partial reply'); +like($t1, qr/Content-Length: 10/, 'more than length - content length'); +like($t1, qr/Content-Range: bytes 990-999\/1000/, + 'more than length - content range'); +like($t1, qr/^X099XXXXXX$/m, 'more than length - correct content'); + +$t1 = http_get_range('/t2.html', 'Range: bytes=990-1990'); +like($t1, qr/206/, 'recoded - 206 partial reply'); +like($t1, qr/Content-Length: 10/, 'recoded - content length'); +like($t1, qr/Content-Range: bytes 990-999\/1000/, 'recoded - content range'); +like($t1, qr/^Y099YYYYYY$/m, 'recoded - correct content'); + +$t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 10-19'); +like($t1, qr/206/, 'multipart - 206 partial reply'); +like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, + 'multipart - content type'); +like($t1, qr/X000XXXXXX/m, 'multipart - content 0-9'); +like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart - content -10 aka 990-999'); +like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart - content 10-19'); + +############################################################################### + +sub http_get_range { + my ($url, $extra) = @_; + return http(<