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

**URL:** <https://www.ruby-forum.com/t/issue-with-if-range-header-and-x-accel-redirect-requests-with-upstream-last-modified-header/211507>\
**Category:** NGINX\
**Created:** [September 6, 2011, 4:46am UTC](https://www.ruby-forum.com/t/issue-with-if-range-header-and-x-accel-redirect-requests-with-upstream-last-modified-header/211507 "2011-09-06T04:46:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 6, 2011, 4:46am UTC](https://www.ruby-forum.com/t/issue-with-if-range-header-and-x-accel-redirect-requests-with-upstream-last-modified-header/211507/1 "2011-09-06T04:46:22Z")

</div>

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?

Thanks  
Leigh

---

<div class="post-metadata">

**Author:** ![Leigh\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Leigh\_D](https://www.ruby-forum.com/u/Leigh_D)\
**Post date:** [September 6, 2011, 8:51am UTC](https://www.ruby-forum.com/t/issue-with-if-range-header-and-x-accel-redirect-requests-with-upstream-last-modified-header/211507/2 "2011-09-06T08:51:06Z")

</div>

Hello!

On Tue, Sep 06, 2011 at 12:45:46PM +1000, Leigh D. wrote:

> 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 D.

---

<div class="post-metadata">

**Author:** ![Leigh\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Leigh\_D](https://www.ruby-forum.com/u/Leigh_D)\
**Post date:** [September 6, 2011, 8:52am UTC](https://www.ruby-forum.com/t/issue-with-if-range-header-and-x-accel-redirect-requests-with-upstream-last-modified-header/211507/3 "2011-09-06T08:52:57Z")

</div>

On 6/09/11 12:45 PM, Leigh D. 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.

Hi again,

I spent some time looking in to this and created a patch that seems to  
fix the problem for me. The issue was in “ngx\_http\_set\_last\_modified” in  
http/modules/ngx\_http\_headers\_filter\_module.c – last\_modified\_time gets  
set to -1 and is then never updated with the new value.

I have no idea how correct this patch is, so I’d greatly appreciate it  
if someone could review this for me.

Thanks  
Leigh

---

<div class="post-metadata">

**Author:** ![Leigh\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Leigh\_D](https://www.ruby-forum.com/u/Leigh_D)\
**Post date:** [September 6, 2011, 9:03am UTC](https://www.ruby-forum.com/t/issue-with-if-range-header-and-x-accel-redirect-requests-with-upstream-last-modified-header/211507/4 "2011-09-06T09:03:28Z")

</div>

Leigh,

You don’t need to be silly at all. Thanks a lot for spotting this one.

–  
Andrew A.  
w. [http://nginx.org](http://nginx.org)

---

<div class="post-metadata">

**Author:** ![Leigh\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ebca7d/32.png) [@Leigh\_D](https://www.ruby-forum.com/u/Leigh_D)\
**Post date:** [September 6, 2011, 9:01am UTC](https://www.ruby-forum.com/t/issue-with-if-range-header-and-x-accel-redirect-requests-with-upstream-last-modified-header/211507/5 "2011-09-06T09:01:36Z")

</div>

On 6/09/11 4:50 PM, Maxim D. wrote:

> Hello!
> 
> Please try the attached patch.

Thanks Maxim – your patch has fixed the problem for me. I feel a little  
silly for spending the time to come up with my own patch, but at least I  
know more about nginx now than I did this morning 🙂

Thanks  
Leigh
