Skip to content

Instantly share code, notes, and snippets.

@jonathanio
Last active August 29, 2015 14:03
Show Gist options
  • Save jonathanio/c916738a23f4398b77d2 to your computer and use it in GitHub Desktop.
Save jonathanio/c916738a23f4398b77d2 to your computer and use it in GitHub Desktop.
nginx Patch
Description: Allow ranges on upstream cacheable/buffered files.
Added support for allowing ranges within upstream cachable/buffered
files in order to properly support RFC2616:
If a proxy that supports ranges receives a Range request, forwards
the request to an inbound server, and receives an entire entity in
reply, it SHOULD only return the requested range to its client. It
SHOULD store the entire received response in its cache if that is
consistent with its cache allocation policies.
Requires proxy_buffering on to be set.
Author: Jonathan Wright <jonathanw@blinkbox.com>
---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:
Origin: other, https://github.com/nginx/nginx/commit/d2ce3a1fcb5e0f7f27d22293832ced78b2cc744d
Forwarded: no
Reviewed-By: Jonathan Wright <jonathanw@blinkbox.com>
Last-Update: 2014-07-10
--- nginx-1.4.4.orig/src/http/ngx_http_upstream.c
+++ nginx-1.4.4/src/http/ngx_http_upstream.c
@@ -4044,7 +4044,10 @@
if (r->cached) {
r->allow_ranges = 1;
return NGX_OK;
-
+ } else if (r->upstream->cacheable || r->upstream->buffering) {
+ r->allow_ranges = 1;
+ r->single_range = 1;
+ return NGX_OK;
}
#endif
--- nginx-1.4.4.orig/src/http/modules/ngx_http_range_filter_module.c
+++ nginx-1.4.4/src/http/modules/ngx_http_range_filter_module.c
@@ -148,6 +148,7 @@
{
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 @@
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);
--- nginx-1.4.4.orig/src/http/ngx_http_request.h
+++ nginx-1.4.4/src/http/ngx_http_request.h
@@ -526,6 +526,7 @@
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment