# HG changeset patch # User Sergey Kandaurov # Date 1490358346 -10800 # Node ID 8241ebbe753d306468008500c8fa2e35ac44902f # Parent 57673c7257a3eec84f7d010c3125ab6072cbb22c Tests: added perl header_out content-length tests with ranges. diff --git a/perl.t b/perl.t --- a/perl.t +++ b/perl.t @@ -23,7 +23,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(13) +my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(16) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -65,6 +65,25 @@ http { }'; } + location /range { + perl 'sub { + use warnings; + use strict; + + my $r = shift; + + $r->header_out("Content-Length", "42"); + $r->allow_ranges(); + $r->send_http_header("text/plain"); + + return OK if $r->header_only; + + $r->print("x" x 42); + + return OK; + }'; + } + location /body { perl 'sub { use warnings; @@ -136,6 +155,24 @@ like(http( . 'Host: localhost' . CRLF . CRLF ), qr/xff: foo1, foo2/, 'perl header_in xff2'); +# headers_out content-length tests with range filter + +like(http_get('/range'), qr/Content-Length: 42.*^x{42}$/ms, + 'perl header_out content-length'); + +like(http( + 'GET /range HTTP/1.0' . CRLF + . 'Host: localhost' . CRLF + . 'Range: bytes=0-1' . CRLF . CRLF +), qr/Content-Length: 2.*^xx$/ms, 'perl header_out content-length range'); + +like(http( + 'GET /range HTTP/1.0' . CRLF + . 'Host: localhost' . CRLF + . 'Range: bytes=0-1,3-5' . CRLF . CRLF +), qr/Content-Length: (?!42).*^xx\x0d.*^xxx\x0d/ms, + 'perl header_out content-length multipart'); + # various request body tests like(http(