Hi,

To illustrate the fix I mentioned -- please find the patches attached.

Thanks.

-- 
Mindaugas
diff -r 19a54ba76c04 src/http/modules/ngx_http_slice_filter_module.c
--- a/src/http/modules/ngx_http_slice_filter_module.c   Wed May 11 17:55:30 
2016 +0300
+++ b/src/http/modules/ngx_http_slice_filter_module.c   Wed May 11 16:34:47 
2016 +0100
@@ -96,6 +96,20 @@
 static ngx_http_output_body_filter_pt    ngx_http_next_body_filter;
 
 
+static ngx_http_slice_ctx_t *
+ngx_http_slice_getctx(ngx_http_request_t *r)
+{
+    ngx_http_slice_ctx_t *ctx;
+
+    ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
+    if (ctx == NULL && r != r->main) {
+        ngx_http_request_t *p = r->parent;
+        return ngx_http_get_module_ctx(p, ngx_http_slice_filter_module);
+    }
+    return ctx;
+}
+
+
 static ngx_int_t
 ngx_http_slice_header_filter(ngx_http_request_t *r)
 {
@@ -106,7 +120,7 @@
     ngx_http_slice_loc_conf_t       *slcf;
     ngx_http_slice_content_range_t   cr;
 
-    ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
+    ctx = ngx_http_slice_getctx(r);
     if (ctx == NULL) {
         return ngx_http_next_header_filter(r);
     }
@@ -213,7 +227,7 @@
     ngx_http_slice_ctx_t       *ctx;
     ngx_http_slice_loc_conf_t  *slcf;
 
-    ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
+    ctx = ngx_http_slice_getctx(r);
 
     if (ctx == NULL || r != r->main) {
         return ngx_http_next_body_filter(r, in);
@@ -248,8 +262,6 @@
         return NGX_ERROR;
     }
 
-    ngx_http_set_ctx(sr, ctx, ngx_http_slice_filter_module);
-
     slcf = ngx_http_get_module_loc_conf(r, ngx_http_slice_filter_module);
 
     ctx->range.len = ngx_sprintf(ctx->range.data, "bytes=%O-%O", ctx->start,
@@ -375,7 +387,7 @@
     ngx_http_slice_ctx_t       *ctx;
     ngx_http_slice_loc_conf_t  *slcf;
 
-    ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);
+    ctx = ngx_http_slice_getctx(r);
 
     if (ctx == NULL) {
         if (r != r->main || r->headers_out.status) {
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 {
_______________________________________________
nginx-devel mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to