diff -r 724fcee9a355 slice.t --- a/slice.t Thu May 05 23:33:02 2016 +0300 +++ b/slice.t Fri May 06 11:47:03 2016 +0100 @@ -23,7 +23,7 @@ select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http proxy cache fastcgi slice shmem/) - ->plan(72); + ->plan(80); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -43,6 +43,8 @@ fastcgi_cache_path %%TESTDIR%%/cache2 keys_zone=NAME2:1m; fastcgi_cache_key $uri$is_args$args$slice_range; + proxy_cache_path %%TESTDIR%%/cache3 keys_zone=NAME3:1m; + server { listen 127.0.0.1:8080; server_name localhost; @@ -78,6 +80,28 @@ add_header X-Cache-Status $upstream_cache_status; } + + location /cache-redirect/ { + error_page 550 = @named_cache_redirect; + + return 550; + } + + location @named_cache_redirect { + slice 2; + + proxy_cache_key "t$is_args$args$slice_range"; + + proxy_pass http://127.0.0.1:8081/t$is_args$args; + + proxy_cache NAME3; + + proxy_set_header Range $slice_range; + + proxy_cache_valid 200 206 1h; + + add_header X-Cache-Status $upstream_cache_status; + } } server { @@ -242,6 +266,23 @@ 'fastcgi slice next'); } +# Tests for slicing the result of a named location redirection. +my @e; +like(http_get('/cache-redirect/t'), qr/ 200 .*012345678$/ms, 'no range'); +like($t->read_file("/cache3/2426bc95860bd743e0e1a8661f920dec"), # hash of "/tbytes=0-1" + '/KEY: tbytes=0-1/', "cache key incorrect"); +@e = glob $t->testdir()."/cache3/*"; +is(scalar @e, 5, "unexpected number of cache entries found"); + +$r = get('/cache-redirect/t?one', "Range: bytes=2-2"); +like($r, qr/ 206 /, 'one - 206 partial reply'); +like($r, qr/^2$/m, 'one - correct content'); +like($r, qr/Status: MISS/m, 'one - cache-redirect status'); +like($t->read_file("/cache3/3ce34387e5dda3267c0a262c030edc94"), # hash of "/t?onebytes=2-3" + '/KEY: t\?onebytes=2-3/', "one - cache key incorrect"); +@e = glob $t->testdir()."/cache3/*"; +is(scalar @e, 6, "one - unexpected number of cache entries found"); + ############################################################################### sub get {