]> git.kaiwu.me - nginx.git/commitdiff
Range filter: single_range flag in request.
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 21 Mar 2014 15:33:21 +0000 (19:33 +0400)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 21 Mar 2014 15:33:21 +0000 (19:33 +0400)
If set, it means that response body is going to be in more than one buffer,
hence only range requests with a single range should be honored.

The flag is now used by mp4 and cacheable upstream responses, thus allowing
range requests of mp4 files with start/end, as well as range processing
on a first request to a not-yet-cached files with proxy_cache.

Notably this makes it possible to play mp4 files (with proxy_cache, or with
mp4 module) on iOS devices, as byte-range support is required by Apple.

src/http/modules/ngx_http_mp4_module.c
src/http/modules/ngx_http_range_filter_module.c
src/http/ngx_http_request.h
src/http/ngx_http_upstream.c

index 647dff4571ae9e5c323b107fa3bc4edbf07e4a6d..d0a6a8e031f135abe81917f6474ed40d8805e033 100644 (file)
@@ -571,7 +571,7 @@ ngx_http_mp4_handler(ngx_http_request_t *r)
     }
 
     if (start >= 0) {
-        r->allow_ranges = 0;
+        r->single_range = 1;
 
         mp4 = ngx_pcalloc(r->pool, sizeof(ngx_http_mp4_file_t));
         if (mp4 == NULL) {
index bcc64fd30c2c0380a794bb78f009e003c6644b5c..6a65e48498dbba1bce084095a6a47823a0c0b2f6 100644 (file)
@@ -148,6 +148,7 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
 {
     time_t                        if_range_time;
     ngx_str_t                    *if_range, *etag;
+    ngx_uint_t                    ranges;
     ngx_http_core_loc_conf_t     *clcf;
     ngx_http_range_filter_ctx_t  *ctx;
 
@@ -227,7 +228,9 @@ parse:
         return NGX_ERROR;
     }
 
-    switch (ngx_http_range_parse(r, ctx, clcf->max_ranges)) {
+    ranges = r->single_range ? 1 : clcf->max_ranges;
+
+    switch (ngx_http_range_parse(r, ctx, ranges)) {
 
     case NGX_OK:
         ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module);
index a1295e79913c888adc0f7186d499dbf57d49eaf4..705c4e904568ce4041ba572eb530300a979415a5 100644 (file)
@@ -528,6 +528,7 @@ struct ngx_http_request_s {
     unsigned                          filter_need_in_memory:1;
     unsigned                          filter_need_temporary:1;
     unsigned                          allow_ranges:1;
+    unsigned                          single_range:1;
 
 #if (NGX_STAT_STUB)
     unsigned                          stat_reading:1;
index cf9ca0d5cf5fbf0bd499f49ba788231106d86961..040bda10623519ae31c8a0f81bad8252b2579f90 100644 (file)
@@ -4183,7 +4183,12 @@ ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r,
     if (r->cached) {
         r->allow_ranges = 1;
         return NGX_OK;
+    }
 
+    if (r->upstream->cacheable) {
+        r->allow_ranges = 1;
+        r->single_range = 1;
+        return NGX_OK;
     }
 
 #endif