Mercurial > hg > nginx-quic
diff src/http/modules/ngx_http_range_filter_module.c @ 4062:82738a316a54
The "max_ranges" directive.
"max_ranges 0" disables ranges support at all,
"max_ranges 1" allows the single range, etc.
By default number of ranges is unlimited, to be precise, 2^31-1.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 31 Aug 2011 09:40:55 +0000 |
parents | bd2ec6ce5d58 |
children | 8d70904b6c48 |
line wrap: on
line diff
--- a/src/http/modules/ngx_http_range_filter_module.c +++ b/src/http/modules/ngx_http_range_filter_module.c @@ -59,7 +59,7 @@ typedef struct { static ngx_int_t ngx_http_range_parse(ngx_http_request_t *r, - ngx_http_range_filter_ctx_t *ctx); + ngx_http_range_filter_ctx_t *ctx, ngx_uint_t ranges); static ngx_int_t ngx_http_range_singlepart_header(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx); static ngx_int_t ngx_http_range_multipart_header(ngx_http_request_t *r, @@ -146,6 +146,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) { time_t if_range; + ngx_http_core_loc_conf_t *clcf; ngx_http_range_filter_ctx_t *ctx; if (r->http_version < NGX_HTTP_VERSION_10 @@ -157,6 +158,12 @@ ngx_http_range_header_filter(ngx_http_re return ngx_http_next_header_filter(r); } + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + if (clcf->max_ranges == 0) { + return ngx_http_next_header_filter(r); + } + if (r->headers_in.range == NULL || r->headers_in.range->value.len < 7 || ngx_strncasecmp(r->headers_in.range->value.data, @@ -191,7 +198,7 @@ ngx_http_range_header_filter(ngx_http_re return NGX_ERROR; } - switch (ngx_http_range_parse(r, ctx)) { + switch (ngx_http_range_parse(r, ctx, clcf->max_ranges)) { case NGX_OK: ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module); @@ -231,7 +238,8 @@ next_filter: static ngx_int_t -ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx) +ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx, + ngx_uint_t ranges) { u_char *p; off_t start, end, size, content_length; @@ -314,6 +322,10 @@ ngx_http_range_parse(ngx_http_request_t range->end = end; size += end - start; + + if (--ranges == 0) { + break; + } } if (*p++ != ',') {