# Sendfile headers

**URL:** <https://www.ruby-forum.com/t/sendfile-headers/159042>\
**Category:** Radiant CMS\
**Created:** [January 30, 2009, 7:24pm UTC](https://www.ruby-forum.com/t/sendfile-headers/159042 "2009-01-30T19:24:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [January 30, 2009, 7:24pm UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/1 "2009-01-30T19:24:51Z")

</div>

Last night at our little hack session at John’s, I added the ability to  
support X-Accel-Redirect headers for nginx. It would be great if  
someone could test this addition with nginx. In config/environment.rb,  
put this line inside the config.after\_initialize block:

ResponseCache.defaults[:use\_x\_accel\_redirect] = true

Since I have [seancribbs.com](http://seancribbs.com) running the latest and hosted using  
Apache/Passenger, I decided to turn on X-Sendfile headers. However,  
Apache doesn’t seem to recognize them and just serves up a blank  
response (with the X-Sendfile header included in the response). So my  
questions are two:

1. Is this just a side-effect of using Passenger? Would a proxy scenario  
(Mongrel, Thin, etc) work?
2. Is there something different Radiant should be doing with other  
headers to make it work?

Additionally, if anyone could look into conditional GETs and make sure  
we’re doing it right, that would be great.

Sean

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [January 31, 2009, 12:13am UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/2 "2009-01-31T00:13:42Z")

</div>

It seems my problem is that “EnableSendfile” in Apache core is not the  
same thing as X-Sendfile. Installing mod\_xsendfile fixes the problem.

That said, anyone who can test with nginx - please report!

Sean

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [January 31, 2009, 2:06am UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/3 "2009-01-31T02:06:41Z")

</div>

Once a page has comments there is a link in the admin of that page to  
view comments and if I click on it I get an application error. This  
is what the production log says:

Parameters: {“action”=\>“index”, “page\_id”=\>“5”, “controller”=\>“admin/  
comments”}  
Cookie set: session\_token=a7c8382524930cc092981330cf62fc75f8a68582;  
path=/; expires=Sat, 14 Feb 2009 00:43:07 GMT  
Rendering template within layouts/application  
Rendering admin/comments/index

ActionView::TemplateError (undefined method `page\_edit\_url’ for  
#ActionView::Base:0x93fe360) on line #1 of admin/comments/index.rhtml:  
1:

# \<%= @page.nil? ? “#{params[:status].titleize if params[:status]} Comments” : “#{@page.comments\_count} #{pluralize(@page.comments\_count, “Comment”)} on #{link\_to(@page.title, page\_edit\_url(@page.id))}” %\>
  
2:  
3: 

4: View:

```
 vendor/extensions/comments/app/views/admin/comments/index.rhtml:

```

1:in  
`_run_erb_47vendor47extensions47comments47app47views47admin47comments47index46rhtml ' vendor/rails/actionpack/lib/action_view/base.rb:342:in`send’  
vendor/rails/actionpack/lib/action\_view/base.rb:342:in `execute' vendor/rails/actionpack/lib/action_view/template_handlers/ compilable.rb:29:in`send’  
vendor/rails/actionpack/lib/action\_view/template\_handlers/  
compilable.rb:29:in `render' vendor/rails/actionpack/lib/action_view/template.rb:35:in`render’  
vendor/rails/actionpack/lib/action\_view/template.rb:22:in  
`render_template' vendor/rails/actionpack/lib/action_view/base.rb:248:in`render\_file’

What do I do about this undefined method ‘page\_edit\_url’?

Thanks for any help,

Steven

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [January 31, 2009, 3:07am UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/4 "2009-01-31T03:07:31Z")

</div>

Comments may not have been updated for Radiant 0.7 (which did not  
preserve named routes from earlier versions)  
I believe it should be edit\_admin\_page\_url now, assuming you are on  
edge Radiant.

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 2, 2009, 10:22pm UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/5 "2009-02-02T22:22:59Z")

</div>

Sean, did you use my page\_attachments\_xsendfile extension? If not,  
I’m curious how you set it up.

Jason

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 2, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/6 "2009-02-02T22:51:45Z")

</div>

Jason,

This doesn’t affect page\_attachments. For Apache, I compiled and  
installed mod\_xsendfile, and then added these two directives to my  
Apache config:

XSendfile on  
XSendFileAllowAbove on

And this line to config/environment.rb, inside the after\_initialize  
block:

ResponseCache.defaults[:use\_x\_sendfile] = true

Sean

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [January 31, 2009, 3:41am UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/7 "2009-01-31T03:41:28Z")

</div>

Thank you Jim. I bet you’re right.

Steven

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 3, 2009, 5:03am UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/8 "2009-02-03T05:03:22Z")

</div>

And did it work in production? When I did exactly that (probably 4  
months ago), I found sometimes I would get a blank page or the plain  
text version of the cache file. I didn’t have time to figure it out,  
so I just turned it off again.

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 3, 2009, 5:13am UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/9 "2009-02-03T05:13:18Z")

</div>

I got blank pages occasionally until I installed mod\_xsendfile  
properly. Then, It Just Worked™.

Sean

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 3, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/10 "2009-02-03T14:26:47Z")

</div>

They wouldn’t report a different size (all other headers are preserved),  
but the header gives the file a fast-track through the web-server and  
operating system. Essentially, it tells the OS to stream the file to  
the socket, on OS’s that support it.

Sean

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 3, 2009, 6:11am UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/11 "2009-02-03T06:11:47Z")

</div>

i’ve been using the old x-sendfile patch on nginx and mongrel for about  
a  
year with no blank page issues. after setting up an edge 0.7 in a  
virtual  
machine i was able to run nginx and thin in production mode with no  
blank  
pages in well over a million requests through ab (assuming those blank  
pages  
would report their size differently than the page that was supposed to  
be  
served).

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 8, 2009, 11:02pm UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/12 "2009-02-08T23:02:06Z")

</div>

I installed on 64-bit Ubuntu 8.10. ([seancribbs.com](http://seancribbs.com))

Sean

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [February 8, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/sendfile-headers/159042/13 "2009-02-08T22:54:26Z")

</div>

what type of system did you install mod\_xsendfile on? it’s completely  
broken  
for 64bit httpd on osx.
