summaryrefslogtreecommitdiff
path: root/tests/request.t
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2020-10-10 19:59:55 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2020-10-19 21:40:14 -0400
commit96abd9cfb886679ce85e9cb94ff45a7c42def30a (patch)
tree094080dd5b203aa11ff6f1d376fe77039f79cd06 /tests/request.t
parent2f7839e88fd098a4bb6dd98dfa1ef2ae038c2bcf (diff)
downloadlighttpd-git-96abd9cfb886679ce85e9cb94ff45a7c42def30a.tar.gz
[core] coalesce nearby ranges in Range requests
Range requests must be HTTP/1.1 or later (not HTTP/1.0)
Diffstat (limited to 'tests/request.t')
-rwxr-xr-xtests/request.t76
1 files changed, 49 insertions, 27 deletions
diff --git a/tests/request.t b/tests/request.t
index 75a96350..ba001ad8 100755
--- a/tests/request.t
+++ b/tests/request.t
@@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
-use Test::More tests => 51;
+use Test::More tests => 52;
use LightyTest;
my $tf = LightyTest->new();
@@ -253,80 +253,97 @@ ok($tf->handle_http($t) == 0, 'POST via Transfer-Encoding: chunked; chunked head
## ranges
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=0-3
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '1234' } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 206, 'HTTP-Content' => '1234' } ];
ok($tf->handle_http($t) == 0, 'GET, Range 0-3');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=-3
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
ok($tf->handle_http($t) == 0, 'GET, Range -3');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=3-
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
ok($tf->handle_http($t) == 0, 'GET, Range 3-');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=0-1,3-4
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 206, 'HTTP-Content' => '12345' } ];
+ok($tf->handle_http($t) == 0, 'GET, Range 0-1,3-4 (ranges merged)');
+
+$t->{REQUEST} = ( <<EOF
+GET /100.txt HTTP/1.1
+Host: 123.example.org
+Connection: close
+Range: bytes=0-1,97-98
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF
\r
--fkj49sn38dcn3\r
-Content-Range: bytes 0-1/6\r
+Content-Range: bytes 0-1/100\r
Content-Type: text/plain\r
\r
12\r
--fkj49sn38dcn3\r
-Content-Range: bytes 3-4/6\r
+Content-Range: bytes 97-98/100\r
Content-Type: text/plain\r
\r
-45\r
+hi\r
--fkj49sn38dcn3--\r
EOF
} ];
-ok($tf->handle_http($t) == 0, 'GET, Range 0-1,3-4');
+ok($tf->handle_http($t) == 0, 'GET, Range 0-1,97-98 (ranges not merged)');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=0--
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'GET, Range 0--');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=-2-3
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'GET, Range -2-3');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=-0
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -343,12 +360,13 @@ EOF
ok($tf->handle_http($t) == 0, 'GET, Range -0');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=25-
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -384,31 +402,35 @@ ok($tf->handle_http($t) == 0, 'larger headers');
$t->{REQUEST} = ( <<EOF
-GET /range.pdf HTTP/1.0
+GET /range.pdf HTTP/1.1
+Host: 123.example.org
Range: bytes=0-
+Connection: close
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'GET, Range with range-requests-disabled');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: 0
Range: bytes=0-3
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "12345\n" } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, 'HTTP-Content' => "12345\n" } ];
ok($tf->handle_http($t) == 0, 'GET, Range invalid range-unit (first)');
$t->{REQUEST} = ( <<EOF
-GET /12345.txt HTTP/1.0
+GET /12345.txt HTTP/1.1
Host: 123.example.org
+Connection: close
Range: bytes=0-3
Range: 0
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206 } ];
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 206 } ];
ok($tf->handle_http($t) == 0, 'GET, Range ignore invalid range (second)');
$t->{REQUEST} = ( <<EOF