Welcome! Log In Create A New Profile

Advanced

Re: Issue with If-Range header and X-Accel-Redirect requests with upstream Last-Modified header

Maxim Dounin
September 06, 2011 02:52AM
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
# HG changeset patch
# User Maxim Dounin <mdounin@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);
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Issue with If-Range header and X-Accel-Redirect requests with upstream Last-Modified header

Leigh Dyer September 05, 2011 10:48PM

Re: Issue with If-Range header and X-Accel-Redirect requests with upstream Last-Modified header

Maxim Dounin September 06, 2011 02:52AM

Re: Issue with If-Range header and X-Accel-Redirect requests with upstream Last-Modified header

Leigh Dyer September 06, 2011 03:02AM

Re: Issue with If-Range header and X-Accel-Redirect requests with upstream Last-Modified header

Andrew Alexeev September 06, 2011 03:04AM

Re: Issue with If-Range header and X-Accel-Redirect requests with upstream Last-Modified header

Leigh Dyer September 06, 2011 02:54AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 76
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready