[nginx] slice module issue

Roman Arutyunyan arut at nginx.com
Tue Jun 20 18:43:56 UTC 2017


Hi,

Here's a simple configuration for your case.

    map $http_range $proxy_range {
        volatile;
        ~,       $http_range;
        default  $slice_range;
    }

    server {
        listen 8000;
        location / {
            slice 100;
            proxy_set_header Range $proxy_range;
            proxy_pass http://127.0.0.1:9000;
        }
    }


Note that at request level the slice module is enabled by evaluating the
$slice_range variable.


On Wed, Jun 21, 2017 at 12:45:07AM +0800, 洪志道 wrote:
> Well, it's a good idea, but it's not satisfied yet.
> 
> Now we assume users want to ignore the slice feature
> when the multi-range request is coming.
> 
> How about let slice directive support if scope?
> 
> Such as the following.
> 
> map $http_range $need_slice {
>      ...
> }
> 
> map $slice_range $x_slice_range {
>      ...
> }
> 
> server {
>        if ($need_slice) {
>            slice 100;
>        }
> 
>        proxy_set_header Range $x_slice_range;
> }
> 
> --- 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 Tue Jun 20 12:37:34
> 2017 -0400
> @@ -51,7 +51,8 @@
>  static ngx_command_t  ngx_http_slice_filter_commands[] = {
> 
>      { ngx_string("slice"),
> -
>  NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
> +
>  NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
> +                         NGX_CONF_TAKE1,
>        ngx_conf_set_size_slot,
>        NGX_HTTP_LOC_CONF_OFFSET,
>        offsetof(ngx_http_slice_loc_conf_t, size),
> 
> On Wed, Jun 21, 2017 at 12:31 AM, Roman Arutyunyan <arut at nginx.com> wrote:
> 
> > You can pass a mapped variable to "proxy_set_header Range" which falls back
> > to whatever you want for multi-range requests.
> >
> > On Tue, Jun 20, 2017 at 03:47:02PM +0000, 洪志道 wrote:
> > > If we wan't to slice in the case of multi-page, how to achieve it?
> > >
> > > 洪志道 <hongzhidao at gmail.com>于2017年6月20日 周二23:21写道:
> > >
> > > > You said the module doesn't support multi-range, it means nothing to
> > > > support slice feature through $slice_range.
> > > > Anyway we can avoid it by access handle, but it's still unconvinient.
> > > >
> > > > Roman Arutyunyan <arut at nginx.com>于2017年6月20日 周二21:34写道:
> > > >
> > > >> That would disable slicing at all.
> > > >>
> > > >> On Tue, Jun 20, 2017 at 12:42:30PM +0000, 洪志道 wrote:
> > > >> > Do you think it's better to set $slice_range not found as if
> > multi-range
> > > >> > request?
> > > >> >
> > > >> > Roman Arutyunyan <arut at nginx.com>于2017年6月20日 周二20:09写道:
> > > >> >
> > > >> > > Hi,
> > > >> > >
> > > >> > > On Tue, Jun 20, 2017 at 02:25:14AM +0800, 洪志道 wrote:
> > > >> > > > 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),
> > > >> > >
> > > >> > > Yes, the slice module does not support multi-range.
> > > >> > > The entire file is proxied and processed by the standard range
> > module,
> > > >> > > which has limited multi-range support too.  Particularly,
> > multi-range
> > > >> is
> > > >> > > supported only when returning an entire file from disk.
> > > >> > >
> > > >> > > > 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;
> > > >> > > >       }
> > > >> > > > }
> > > >> > >
> > > >> > > > _______________________________________________
> > > >> > > > nginx-devel mailing list
> > > >> > > > nginx-devel at nginx.org
> > > >> > > > http://mailman.nginx.org/mailman/listinfo/nginx-devel
> > > >> > >
> > > >> > >
> > > >> > > --
> > > >> > > Roman Arutyunyan
> > > >> > > _______________________________________________
> > > >> > > nginx-devel mailing list
> > > >> > > nginx-devel at nginx.org
> > > >> > > http://mailman.nginx.org/mailman/listinfo/nginx-devel
> > > >>
> > > >> > _______________________________________________
> > > >> > nginx-devel mailing list
> > > >> > nginx-devel at nginx.org
> > > >> > http://mailman.nginx.org/mailman/listinfo/nginx-devel
> > > >>
> > > >>
> > > >> --
> > > >> Roman Arutyunyan
> > > >> _______________________________________________
> > > >> nginx-devel mailing list
> > > >> nginx-devel at nginx.org
> > > >> http://mailman.nginx.org/mailman/listinfo/nginx-devel
> > > >
> > > >
> >
> > > _______________________________________________
> > > nginx-devel mailing list
> > > nginx-devel at nginx.org
> > > http://mailman.nginx.org/mailman/listinfo/nginx-devel
> >
> >
> > --
> > Roman Arutyunyan
> > _______________________________________________
> > nginx-devel mailing list
> > nginx-devel at nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx-devel
> >

> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel


-- 
Roman Arutyunyan


More information about the nginx-devel mailing list