<div><div dir="auto">Do you think it's better to set $slice_range not found as if multi-range request?</div><br><div class="gmail_quote"><div>Roman Arutyunyan <<a href="mailto:arut@nginx.com">arut@nginx.com</a>>于2017年6月20日 周二20:09写道:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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, 2-51"<br>
><br>
> We get a response of the whole file that differs from expectation (1-50,<br>
> 2-51).<br>
><br>
> It seems that slice module doesn't support multi-range (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 module,<br>
which has limited multi-range support too. Particularly, multi-range 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_slice_filter_module.c<br>
> --- a/src/http/modules/ngx_http_slice_filter_module.c Mon May 29 23:33:38<br>
> 2017 +0300<br>
> +++ b/src/http/modules/ngx_http_slice_filter_module.c Mon Jun 19 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, 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>
> 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", 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>
> _______________________________________________<br>
> nginx-devel mailing list<br>
> <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
<br>
<br>
--<br>
Roman Arutyunyan<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></blockquote></div></div>