diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:12:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 21:12:02 +0000 |
commit | 77e50caaf2ef81cd91075cf836fed0e75718ffb4 (patch) | |
tree | 53b7b411290b63192fc9e924a3b6b65cdf67e9d0 /debian/vendor-h2o/t/50file-range.t | |
parent | Adding upstream version 1.8.3. (diff) | |
download | dnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.tar.xz dnsdist-77e50caaf2ef81cd91075cf836fed0e75718ffb4.zip |
Adding debian version 1.8.3-2.debian/1.8.3-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/vendor-h2o/t/50file-range.t')
-rw-r--r-- | debian/vendor-h2o/t/50file-range.t | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/debian/vendor-h2o/t/50file-range.t b/debian/vendor-h2o/t/50file-range.t new file mode 100644 index 0000000..826a2d2 --- /dev/null +++ b/debian/vendor-h2o/t/50file-range.t @@ -0,0 +1,100 @@ +use strict; +use warnings; +use Test::More; +use t::Util; + +plan skip_all => 'curl not found' + unless prog_exists('curl'); + +my $all_data = do { + open my $fh, "<", "@{[DOC_ROOT]}/halfdome.jpg" + or die "failed to open file:@{[DOC_ROOT]}/halfdome.jpg:$!"; + undef $/; + <$fh>; +}; + +my $server = spawn_h2o(<< "EOT"); +hosts: + default: + paths: + /: + file.dir: @{[ DOC_ROOT ]} +EOT + +run_with_curl($server, sub { + my ($proto, $port, $curl_cmd) = @_; + $curl_cmd .= " --silent --show-error"; + my $url = "$proto://127.0.0.1:$port/halfdome.jpg"; + + subtest "non-ranged" => sub { + my $resp = `$curl_cmd $url`; + is $resp, $all_data; + }; + + subtest "single-ranged" => sub { + subtest "closed" => sub { + my $resp = `$curl_cmd -r 100-499 $url`; + is $resp, substr($all_data, 100, 400), "content"; + + my $headers = `$curl_cmd -r 100-499 --dump-header /dev/stderr $url 2>&1 > /dev/null`; + like $headers, qr{^content-type:\s*image/jpeg\r$}mi, "content-type"; + like $headers, qr{^content-range:\s*bytes 100-499/@{[length $all_data]}\r}mi, "content-range"; + }; + + subtest "closed-exceed-end" => sub { + my $resp = `$curl_cmd -r 100-999999 $url`; + is $resp, substr($all_data, 100), "content"; + + my $headers = `$curl_cmd -r 100-999999 --dump-header /dev/stderr $url 2>&1 > /dev/null`; + like $headers, qr{^content-type:\s*image/jpeg\r$}mi, "content-type"; + like $headers, qr{^content-range:\s*bytes 100-@{[length($all_data) - 1]}/@{[length $all_data]}\r}mi, "content-range"; + }; + + subtest "closed-unsatisfied" => sub { + my $headers = `$curl_cmd --dump-header /dev/stderr -r 999999-999999 $url 2>&1 > /dev/null`; + like $headers, qr{^HTTP/[^ ]+ 416\s}mi, "416 response"; + }; + + subtest "tail-open" => sub { + my $resp = `$curl_cmd -r 100- $url`; + is $resp, substr($all_data, 100), "content"; + + my $headers = `$curl_cmd -r 100- --dump-header /dev/stderr $url 2>&1 > /dev/null`; + like $headers, qr{^content-type:\s*image/jpeg\r$}mi, "content-type"; + like $headers, qr{^content-range:\s*bytes 100-@{[length($all_data) - 1]}/@{[length $all_data]}\r}mi, "content-range"; + }; + + subtest "suffix" => sub { + my $resp = `$curl_cmd -r -100 $url`; + is $resp, substr($all_data, -100), "content"; + + my $headers = `$curl_cmd -r -100 --dump-header /dev/stderr $url 2>&1 > /dev/null`; + like $headers, qr{^content-type:\s*image/jpeg\r$}mi, "content-type"; + like $headers, qr{^content-range:\s*bytes @{[length($all_data) - 100]}-@{[length($all_data) - 1]}/@{[length $all_data]}\r}mi, "content-range"; + }; + + subtest "suffix-exceed" => sub { + my $resp = `$curl_cmd -r -999999 $url`; + is $resp, $all_data, "content"; + + my $headers = `$curl_cmd -r -999999 --dump-header /dev/stderr $url 2>&1 > /dev/null`; + like $headers, qr{^content-type:\s*image/jpeg\r$}mi, "content-type"; + like $headers, qr{^content-range:\s*bytes 0-@{[length($all_data) - 1]}/@{[length $all_data]}\r}mi, "content-range"; + }; + }; + + subtest "multi-ranged" => sub { + my $resp = `$curl_cmd -r 100-199,1000-1099 $url`; + my @chunks = split /(?:^|\r\n)--[0-9A-Za-z]{20}/s, $resp; + is scalar(@chunks), 4, "number of ranges"; + is $chunks[0], "", "before first boundary"; + is substr($chunks[1], -104), "\r\n\r\n" . substr($all_data, 100, 100), "first chunk"; + is substr($chunks[2], -104), "\r\n\r\n" . substr($all_data, 1000, 100), "second chunk"; + is $chunks[3], "--\r\n", "last boundary"; + + my $headers = `$curl_cmd -r 100-199,1000-1099 --dump-header /dev/stderr $url 2>&1 > /dev/null`; + like $headers, qr{^content-type:\s*multipart/byteranges; boundary=[0-9A-Za-z]{20}\r$}mi, "content-type"; + }; +}); + +done_testing(); |