[nginx] slice module issue

洪志道 hongzhidao at gmail.com
Mon Jun 19 18:25:14 UTC 2017


Hi!

Have a look at the following example first.

server {
      listen  80;

      location / {
          slice 10;
          proxy_set_header  Range $slice_range;
          proxy_pass http://127.0.0.1:81;
      }
}


server {
      listen  81;
       root  html;
}

Then we start a request with curl.
> curl http://my.test.com/ -x 127.1:80 -H "range: bytes=1-50, 2-51"

We get a response of the whole file that differs from expectation (1-50,
2-51).

It seems that slice module doesn't support multi-range (separated by
commas),
but it's confused $slice_range variable is valid.

Please confirm this question and the following patch, thanks!


diff -r 5e05118678af src/http/modules/ngx_http_slice_filter_module.c
--- a/src/http/modules/ngx_http_slice_filter_module.c Mon May 29 23:33:38
2017 +0300
+++ b/src/http/modules/ngx_http_slice_filter_module.c Mon Jun 19 09:35:24
2017 -0400
@@ -389,6 +389,7 @@
     ngx_http_variable_value_t *v, uintptr_t data)
 {
     u_char                     *p;
+    off_t                      start;
     ngx_http_slice_ctx_t       *ctx;
     ngx_http_slice_loc_conf_t  *slcf;

@@ -407,6 +408,13 @@
             return NGX_OK;
         }

+        start = ngx_http_slice_get_start(r);
+
+        if (start == -1) {
+            v->not_found = 1;
+            return NGX_OK;
+        }
+
         ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_slice_ctx_t));
         if (ctx == NULL) {
             return NGX_ERROR;
@@ -419,7 +427,7 @@
             return NGX_ERROR;
         }

-        ctx->start = slcf->size * (ngx_http_slice_get_start(r) /
slcf->size);
+        ctx->start = slcf->size * (start / slcf->size);

         ctx->range.data = p;
         ctx->range.len = ngx_sprintf(p, "bytes=%O-%O", ctx->start,
@@ -460,7 +468,7 @@
     p = h->value.data + 6;

     if (ngx_strchr(p, ',')) {
-        return 0;
+        return -1;
     }

     while (*p == ' ') { p++; }


And this is a better conf.

map $slice_range  $x_slice_range {
        default  $http_range;
        ~           $slice_range;
}

server {
      listen  80;

      location / {
          slice 10;
          proxy_set_header  Range $x_slice_range;
          proxy_pass http://127.0.0.1:81;
      }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20170620/408ec1db/attachment.html>


More information about the nginx-devel mailing list