changeset 1152:8241ebbe753d

Tests: added perl header_out content-length tests with ranges.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 24 Mar 2017 15:25:46 +0300
parents 57673c7257a3
children 818fbc9d1c29
files perl.t
diffstat 1 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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(