]> git.kaiwu.me - nginx.git/commitdiff
Range filter: allowed ranges on empty files (ticket #1031).
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 26 Jun 2017 21:53:46 +0000 (00:53 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 26 Jun 2017 21:53:46 +0000 (00:53 +0300)
As per RFC 2616 / RFC 7233, any range request to an empty file
is expected to result in 416 Range Not Satisfiable response, as
there cannot be a "byte-range-spec whose first-byte-pos is less
than the current length of the entity-body".  On the other hand,
this makes use of byte-range requests inconvenient in some cases,
as reported for the slice module here:

http://mailman.nginx.org/pipermail/nginx-devel/2017-June/010177.html

This commit changes range filter to instead return 200 if the file
is empty and the range requested starts at 0.

src/http/modules/ngx_http_range_filter_module.c

index 8ffca82e64f8378f743bf425f4a74bab76b8b166..7ad9db9dd2bb49738d8003e8aa4d22f9b93ba689 100644 (file)
@@ -382,6 +382,9 @@ ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx,
             if (ranges-- == 0) {
                 return NGX_DECLINED;
             }
+
+        } else if (start == 0) {
+            return NGX_DECLINED;
         }
 
         if (*p++ != ',') {