# HG changeset patch # User Sergey Kandaurov # Date 1504015012 -10800 # Node ID 0c15ba7d19b3a845ba5943f909dadfb6fdf432c0 # Parent 3ca5b0081bc6675f54e41ee7ffe2250e944181af Tests: If-Range tests with proxy. This covers the following cases: - slice filter and If-Range requests (ticket #1357); - If-Range requests with proxy_force_ranges; diff --git a/proxy_force_ranges.t b/proxy_force_ranges.t --- a/proxy_force_ranges.t +++ b/proxy_force_ranges.t @@ -23,7 +23,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(4) +my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(6) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -47,6 +47,11 @@ http { proxy_pass http://127.0.0.1:8081; } + location /proxy/ { + proxy_pass http://127.0.0.1:8081/; + proxy_force_ranges on; + } + location /cache/ { proxy_pass http://127.0.0.1:8081/; proxy_cache NAME; @@ -62,6 +67,8 @@ http { location / { max_ranges 0; + add_header Last-Modified "Mon, 28 Sep 1970 06:00:00 GMT"; + add_header ETag '"59a5401c-8"'; } } } @@ -85,6 +92,23 @@ like(http_get_range('/cache/t.html', 'Ra like(http_get_range('/cache/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms, 'cached multipart range'); +# If-Range HTTP-date request + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.13.5'); + +like(http_get_range('/proxy/t.html', + "Range: bytes=4-\nIf-Range: Mon, 28 Sep 1970 06:00:00 GMT"), + qr/^THIS/m, 'if-range last-modified proxy'); + +} + +# If-Range entity-tag request + +like(http_get_range('/proxy/t.html', + "Range: bytes=4-\nIf-Range: \"59a5401c-8\""), + qr/^THIS/m, 'if-range etag proxy'); + ############################################################################### sub http_get_range { diff --git a/slice.t b/slice.t --- a/slice.t +++ b/slice.t @@ -23,7 +23,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http proxy cache fastcgi slice rewrite/) - ->plan(74); + ->plan(76); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -50,6 +50,14 @@ http { location / { } + location /proxy/ { + slice 2; + + proxy_pass http://127.0.0.1:8081/; + + proxy_set_header Range $slice_range; + } + location /cache/ { slice 2; @@ -223,6 +231,18 @@ like(get('/cache/t?im', "If-Match: bad") like($r, qr/ 206 /, 'if-range - 206 partial reply'); like($r, qr/^34$/m, 'if-range - correct content'); +# respect Last-Modified from non-cacheable response with If-Range + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.13.5'); + +my ($lm) = http_get('/t') =~ /Last-Modified: (.*)/; +$r = get('/proxy/t', "Range: bytes=3-4\nIf-Range: $lm"); +like($r, qr/ 206 /, 'if-range last-modified proxy - 206 partial reply'); +like($r, qr/^34$/m, 'if-range last-modified proxy - correct content'); + +} + $r = get('/cache/t?ifb', "Range: bytes=3-4\nIf-Range: bad"); like($r, qr/ 200 /, 'if-range bad - 200 ok'); like($r, qr/^0123456789abcdef$/m, 'if-range bad - correct content');