Issue with If-Range header and X-Accel-Redirect requests with upstream Last-Modified header
Maxim Dounin
mdounin at mdounin.ru
Tue Sep 6 06:50:18 UTC 2011
Hello!
On Tue, Sep 06, 2011 at 12:45:46PM +1000, Leigh Dyer wrote:
> Hi,
>
> I have nginx 1.0.5 set up as a proxy in front of a Ruby/Ramaze
> application, using X-Accel-Redirect to efficiently handle sending
> large binary files by handing those transfers over to nginx. Range
> requests against this setup work just fine, but "If-Range" headers
> from the client are ignored -- the server always returns the
> requested range, even when the If-Range date doesn't match the
> file's Last-Modified date.
>
> The problem seems to be due to this line in our config:
>
> add_header Last-Modified $upstream_http_last_modified;
>
> This sets the Last-Modified date on file sent to the client to the
> value sent to nginx from Ruby. With this line in the config, I get
> the If-Range issue described above. If I comment this out,
> Last-Modified is taken from the file's mtime instead, but If-Range
> works.
>
> Is there any chance of getting this fixed?
Please try the attached patch.
Maxim Dounin
-------------- next part --------------
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1315291748 -14400
# Node ID e51619385db9694030b9614c833a2b2504b377c9
# Parent 014764a85840606c90317e9f44f2b9fa139cbc8b
Handling of If-Range with add_header Last-Modified.
diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -369,7 +369,8 @@ ngx_http_set_last_modified(ngx_http_requ
old = NULL;
}
- r->headers_out.last_modified_time = -1;
+ r->headers_out.last_modified_time = ngx_http_parse_time(value->data,
+ value->len);
if (old == NULL || *old == NULL) {
@@ -382,6 +383,8 @@ ngx_http_set_last_modified(ngx_http_requ
return NGX_ERROR;
}
+ *old = h;
+
} else {
h = *old;
diff --git a/src/http/modules/ngx_http_range_filter_module.c b/src/http/modules/ngx_http_range_filter_module.c
--- a/src/http/modules/ngx_http_range_filter_module.c
+++ b/src/http/modules/ngx_http_range_filter_module.c
@@ -173,7 +173,11 @@ ngx_http_range_header_filter(ngx_http_re
goto next_filter;
}
- if (r->headers_in.if_range && r->headers_out.last_modified_time != -1) {
+ if (r->headers_in.if_range) {
+
+ if (r->headers_out.last_modified_time == (time_t) -1) {
+ goto next_filter;
+ }
if_range = ngx_http_parse_time(r->headers_in.if_range->value.data,
r->headers_in.if_range->value.len);
More information about the nginx
mailing list