<div dir="ltr"><div class="gmail_extra">Wow, thank you for your patience.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Perfect!!!</div><div class="gmail_extra"><br></div><div class="gmail_extra">Btw, The ctx of slice module is really a good skill.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 21, 2017 at 2:43 AM, Roman Arutyunyan <span dir="ltr"><<a href="mailto:arut@nginx.com" target="_blank">arut@nginx.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Here's a simple configuration for your case.<br>
<br>
map $http_range $proxy_range {<br>
volatile;<br>
~, $http_range;<br>
default $slice_range;<br>
}<br>
<br>
server {<br>
listen 8000;<br>
location / {<br>
slice 100;<br>
proxy_set_header Range $proxy_range;<br>
proxy_pass <a href="http://127.0.0.1:9000" rel="noreferrer" target="_blank">http://127.0.0.1:9000</a>;<br>
}<br>
}<br>
<br>
<br>
Note that at request level the slice module is enabled by evaluating the<br>
$slice_range variable.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Wed, Jun 21, 2017 at 12:45:07AM +0800, 洪志道 wrote:<br>
> Well, it's a good idea, but it's not satisfied yet.<br>
><br>
> Now we assume users want to ignore the slice feature<br>
> when the multi-range request is coming.<br>
><br>
> How about let slice directive support if scope?<br>
><br>
> Such as the following.<br>
><br>
> map $http_range $need_slice {<br>
> ...<br>
> }<br>
><br>
> map $slice_range $x_slice_range {<br>
> ...<br>
> }<br>
><br>
> server {<br>
> if ($need_slice) {<br>
> slice 100;<br>
> }<br>
><br>
> proxy_set_header Range $x_slice_range;<br>
> }<br>
><br>
> --- a/src/http/modules/ngx_http_<wbr>slice_filter_module.c Mon May 29 23:33:38<br>
> 2017 +0300<br>
> +++ b/src/http/modules/ngx_http_<wbr>slice_filter_module.c Tue Jun 20 12:37:34<br>
> 2017 -0400<br>
> @@ -51,7 +51,8 @@<br>
> static ngx_command_t ngx_http_slice_filter_<wbr>commands[] = {<br>
><br>
> { ngx_string("slice"),<br>
> -<br>
> NGX_HTTP_MAIN_CONF|NGX_HTTP_<wbr>SRV_CONF|NGX_HTTP_LOC_CONF|<wbr>NGX_CONF_TAKE1,<br>
> +<br>
> NGX_HTTP_MAIN_CONF|NGX_HTTP_<wbr>SRV_CONF|NGX_HTTP_LOC_CONF|<wbr>NGX_HTTP_LIF_CONF<br>
> + NGX_CONF_TAKE1,<br>
> ngx_conf_set_size_slot,<br>
> NGX_HTTP_LOC_CONF_OFFSET,<br>
> offsetof(ngx_http_slice_loc_<wbr>conf_t, size),<br>
><br>
> On Wed, Jun 21, 2017 at 12:31 AM, Roman Arutyunyan <<a href="mailto:arut@nginx.com">arut@nginx.com</a>> wrote:<br>
><br>
> > You can pass a mapped variable to "proxy_set_header Range" which falls back<br>
> > to whatever you want for multi-range requests.<br>
> ><br>
> > On Tue, Jun 20, 2017 at 03:47:02PM +0000, 洪志道 wrote:<br>
> > > If we wan't to slice in the case of multi-page, how to achieve it?<br>
> > ><br>
> > > 洪志道 <<a href="mailto:hongzhidao@gmail.com">hongzhidao@gmail.com</a>><wbr>于2017年6月20日 周二23:21写道:<br>
> > ><br>
> > > > You said the module doesn't support multi-range, it means nothing to<br>
> > > > support slice feature through $slice_range.<br>
> > > > Anyway we can avoid it by access handle, but it's still unconvinient.<br>
> > > ><br>
> > > > Roman Arutyunyan <<a href="mailto:arut@nginx.com">arut@nginx.com</a>>于2017年6月20日 周二21:34写道:<br>
> > > ><br>
> > > >> That would disable slicing at all.<br>
> > > >><br>
> > > >> On Tue, Jun 20, 2017 at 12:42:30PM +0000, 洪志道 wrote:<br>
> > > >> > Do you think it's better to set $slice_range not found as if<br>
> > multi-range<br>
> > > >> > request?<br>
> > > >> ><br>
> > > >> > Roman Arutyunyan <<a href="mailto:arut@nginx.com">arut@nginx.com</a>>于2017年6月20日 周二20:09写道:<br>
> > > >> ><br>
> > > >> > > Hi,<br>
> > > >> > ><br>
> > > >> > > On Tue, Jun 20, 2017 at 02:25:14AM +0800, 洪志道 wrote:<br>
> > > >> > > > Hi!<br>
> > > >> > > ><br>
> > > >> > > > Have a look at the following example first.<br>
> > > >> > > ><br>
> > > >> > > > server {<br>
> > > >> > > > listen 80;<br>
> > > >> > > ><br>
> > > >> > > > location / {<br>
> > > >> > > > slice 10;<br>
> > > >> > > > proxy_set_header Range $slice_range;<br>
> > > >> > > > proxy_pass <a href="http://127.0.0.1:81" rel="noreferrer" target="_blank">http://127.0.0.1:81</a>;<br>
> > > >> > > > }<br>
> > > >> > > > }<br>
> > > >> > > ><br>
> > > >> > > ><br>
> > > >> > > > server {<br>
> > > >> > > > listen 81;<br>
> > > >> > > > root html;<br>
> > > >> > > > }<br>
> > > >> > > ><br>
> > > >> > > > Then we start a request with curl.<br>
> > > >> > > > > curl <a href="http://my.test.com/" rel="noreferrer" target="_blank">http://my.test.com/</a> -x 127.1:80 -H "range: bytes=1-50,<br>
> > 2-51"<br>
> > > >> > > ><br>
> > > >> > > > We get a response of the whole file that differs from<br>
> > expectation<br>
> > > >> (1-50,<br>
> > > >> > > > 2-51).<br>
> > > >> > > ><br>
> > > >> > > > It seems that slice module doesn't support multi-range<br>
> > (separated by<br>
> > > >> > > > commas),<br>
> > > >> > ><br>
> > > >> > > Yes, the slice module does not support multi-range.<br>
> > > >> > > The entire file is proxied and processed by the standard range<br>
> > module,<br>
> > > >> > > which has limited multi-range support too. Particularly,<br>
> > multi-range<br>
> > > >> is<br>
> > > >> > > supported only when returning an entire file from disk.<br>
> > > >> > ><br>
> > > >> > > > but it's confused $slice_range variable is valid.<br>
> > > >> > > ><br>
> > > >> > > > Please confirm this question and the following patch, thanks!<br>
> > > >> > > ><br>
> > > >> > > ><br>
> > > >> > > > diff -r 5e05118678af src/http/modules/ngx_http_<br>
> > slice_filter_module.c<br>
> > > >> > > > --- a/src/http/modules/ngx_http_<wbr>slice_filter_module.c Mon May<br>
> > 29<br>
> > > >> 23:33:38<br>
> > > >> > > > 2017 +0300<br>
> > > >> > > > +++ b/src/http/modules/ngx_http_<wbr>slice_filter_module.c Mon Jun<br>
> > 19<br>
> > > >> 09:35:24<br>
> > > >> > > > 2017 -0400<br>
> > > >> > > > @@ -389,6 +389,7 @@<br>
> > > >> > > > ngx_http_variable_value_t *v, uintptr_t data)<br>
> > > >> > > > {<br>
> > > >> > > > u_char *p;<br>
> > > >> > > > + off_t start;<br>
> > > >> > > > ngx_http_slice_ctx_t *ctx;<br>
> > > >> > > > ngx_http_slice_loc_conf_t *slcf;<br>
> > > >> > > ><br>
> > > >> > > > @@ -407,6 +408,13 @@<br>
> > > >> > > > return NGX_OK;<br>
> > > >> > > > }<br>
> > > >> > > ><br>
> > > >> > > > + start = ngx_http_slice_get_start(r);<br>
> > > >> > > > +<br>
> > > >> > > > + if (start == -1) {<br>
> > > >> > > > + v->not_found = 1;<br>
> > > >> > > > + return NGX_OK;<br>
> > > >> > > > + }<br>
> > > >> > > > +<br>
> > > >> > > > ctx = ngx_pcalloc(r->pool,<br>
> > sizeof(ngx_http_slice_ctx_t));<br>
> > > >> > > > if (ctx == NULL) {<br>
> > > >> > > > return NGX_ERROR;<br>
> > > >> > > > @@ -419,7 +427,7 @@<br>
> > > >> > > > return NGX_ERROR;<br>
> > > >> > > > }<br>
> > > >> > > ><br>
> > > >> > > > - ctx->start = slcf->size * (ngx_http_slice_get_start(r)<br>
> > /<br>
> > > >> > > > slcf->size);<br>
> > > >> > > > + ctx->start = slcf->size * (start / slcf->size);<br>
> > > >> > > ><br>
> > > >> > > > ctx->range.data = p;<br>
> > > >> > > > ctx->range.len = ngx_sprintf(p, "bytes=%O-%O",<br>
> > ctx->start,<br>
> > > >> > > > @@ -460,7 +468,7 @@<br>
> > > >> > > > p = h->value.data + 6;<br>
> > > >> > > ><br>
> > > >> > > > if (ngx_strchr(p, ',')) {<br>
> > > >> > > > - return 0;<br>
> > > >> > > > + return -1;<br>
> > > >> > > > }<br>
> > > >> > > ><br>
> > > >> > > > while (*p == ' ') { p++; }<br>
> > > >> > > ><br>
> > > >> > > ><br>
> > > >> > > > And this is a better conf.<br>
> > > >> > > ><br>
> > > >> > > > map $slice_range $x_slice_range {<br>
> > > >> > > > default $http_range;<br>
> > > >> > > > ~ $slice_range;<br>
> > > >> > > > }<br>
> > > >> > > ><br>
> > > >> > > > server {<br>
> > > >> > > > listen 80;<br>
> > > >> > > ><br>
> > > >> > > > location / {<br>
> > > >> > > > slice 10;<br>
> > > >> > > > proxy_set_header Range $x_slice_range;<br>
> > > >> > > > proxy_pass <a href="http://127.0.0.1:81" rel="noreferrer" target="_blank">http://127.0.0.1:81</a>;<br>
> > > >> > > > }<br>
> > > >> > > > }<br>
> > > >> > ><br>
> > > >> > > > ______________________________<wbr>_________________<br>
> > > >> > > > nginx-devel mailing list<br>
> > > >> > > > <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
> > > >> > > > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
> > > >> > ><br>
> > > >> > ><br>
> > > >> > > --<br>
> > > >> > > Roman Arutyunyan<br>
> > > >> > > ______________________________<wbr>_________________<br>
> > > >> > > nginx-devel mailing list<br>
> > > >> > > <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
> > > >> > > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
> > > >><br>
> > > >> > ______________________________<wbr>_________________<br>
> > > >> > nginx-devel mailing list<br>
> > > >> > <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
> > > >> > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
> > > >><br>
> > > >><br>
> > > >> --<br>
> > > >> Roman Arutyunyan<br>
> > > >> ______________________________<wbr>_________________<br>
> > > >> nginx-devel mailing list<br>
> > > >> <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
> > > >> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
> > > ><br>
> > > ><br>
> ><br>
> > > ______________________________<wbr>_________________<br>
> > > nginx-devel mailing list<br>
> > > <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
> > > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
> ><br>
> ><br>
> > --<br>
> > Roman Arutyunyan<br>
> > ______________________________<wbr>_________________<br>
> > nginx-devel mailing list<br>
> > <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
> > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
> ><br>
<br>
> ______________________________<wbr>_________________<br>
> nginx-devel mailing list<br>
> <a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
<br>
<br>
--<br>
Roman Arutyunyan<br>
______________________________<wbr>_________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a></div></div></blockquote></div><br></div></div>