# X\_send\_file sends a 1 byte file

**URL:** <https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660>\
**Category:** Mongrel\
**Created:** [June 17, 2008, 8:35am UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660 "2008-06-17T08:35:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![glsmyth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@glsmyth](https://www.ruby-forum.com/u/glsmyth)\
**Post date:** [June 17, 2008, 8:35am UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660/1 "2008-06-17T08:35:31Z")

</div>

Hello,

sorry if creating a dupe…

I’m trying to download files to authenticated users in my app. I’ve set  
up x\_send\_file. All seems to be correct to me, however when I try to  
download any file, I get a 1-byte long file downloaded.

I am getting this already in development - so no Apache, no lighthttpd,  
just a mongrel\_rails start in the root of my app.

Any help/hint would be appreciated.

Thanks,  
George

---

<div class="post-metadata">

**Author:** ![glsmyth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@glsmyth](https://www.ruby-forum.com/u/glsmyth)\
**Post date:** [June 17, 2008, 9:24am UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660/2 "2008-06-17T09:24:08Z")

</div>

On Mon, Jun 16, 2008 at 11:35 PM, George Schreiber  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Any help/hint would be appreciated.

This only works with a frontend httpd to intercept the X-Sendfile  
response header and send the actual file.

Without a frontend httpd, you’re seeing the expected result. Use  
firebug to verify.

jeremy

---

<div class="post-metadata">

**Author:** ![glsmyth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@glsmyth](https://www.ruby-forum.com/u/glsmyth)\
**Post date:** [June 17, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660/3 "2008-06-17T18:33:13Z")

</div>

On Tue, Jun 17, 2008 at 1:23 AM, Jeremy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> response header and send the actual file.
> 
> Without a frontend httpd, you’re seeing the expected result. Use  
> firebug to verify.

To expand on what Jeremy said, x\_send\_file just sets an HTTP header,  
X-Sendfile, in the response.

It’s up to whatever is running in front of your processes to see that  
header and then to do something with it.

So, in order to adequately test it, you will have to have _something_  
in front of your processes which handle it. Also be aware that only  
some web servers implement X-Sendfile (Apache, via mod\_xsendfile,  
lighttpd natively [it originated with them], and Swiftiply are the  
three that come to mind). Litespeed has their own redirect syntax  
(which they spin to make it sound better than the others). Nginx also  
has it’s own approach with x-accel-redirect (which Swiftiply may  
support in the future, as well).

So if you are using any one of those mechanisms for delivering static  
file downloads, to test it you will have to have a compatible front  
end running, and without some (fairly minor) code changes, you are  
locked into whatever one you choose to use.

Hope this helps.

Kirk H.

---

<div class="post-metadata">

**Author:** ![glsmyth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@glsmyth](https://www.ruby-forum.com/u/glsmyth)\
**Post date:** [June 17, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660/4 "2008-06-17T19:50:11Z")

</div>

If you do have X-SendFile installed make sure your settings for it are  
correct as well. I got caught by this the other day too. I had  
forgotten to add…

|XSendFile on  
XSendFileAllowAbove on

|||to my VirtualHost config.

FYI.

matte - webmaster  
removed\_email\_address@domain.invalid  
||

---

<div class="post-metadata">

**Author:** ![glsmyth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@glsmyth](https://www.ruby-forum.com/u/glsmyth)\
**Post date:** [June 17, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660/5 "2008-06-17T21:47:07Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

> > > > > “Kirk” == Kirk H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:  
> > > > > Kirk\> So, in order to adequately test it, you will have to have  
> > > > > Kirk\> _something_ in front of your processes which handle it. Also  
> > > > > Kirk\> be aware that only some web servers implement X-Sendfile

Good point.

I have some scripts that setup apache.conf to run in the current  
directory, as current user, on a high-port. It would be all rake tasks,  
but my rake task actually just invokes a Makefile and shell scripts,  
because I wrote this code for a non-ruby project originally.  
(My makefile also arranges to build a mysql cluster locally too)

I would like to have system level tests of some kind to help with  
this kind of thing too. I haven’t looked at how the mongrel code itself  
gets tested — maybe there is something there that can help?

* * *

Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Director – Consumer Desktop Development, Simtone Corporation, Ottawa,  
Canada  
Personal: [Michael Richardson's Directory](http://www.sandelman.ca/mcr/)

SIMtone Corporation fundamentally transforms computing into simple,  
secure, and very low-cost network-provisioned services pervasively  
accessible by everyone. Learn more at [www.simtone.net](http://www.simtone.net) and  
[www.SIMtoneVDU.com](http://www.SIMtoneVDU.com)

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.6 (GNU/Linux)

iQDVAwUBSFgS7e0sRu40D6vCAQI4ogYAoJkW4C7P7acV+ZRoCU6Bb46Wt3M6qwzG  
0SUWXzs2xvGPFmcpdqjBIIHj/D+XCNZxIPgFtj62yFmZTzl320sJvjcrA/SOteRD  
o4ik+wXHFmIKum3Yz4i2qSJFNJmZJ4Juv7p9Np1b6M0W3Gjz4IbKox1oteCicnTW  
e18hgZg5009LxjPxwNXnKVZbJQmdqGM3xB2MMK3eBOkN5HkbwaBConrhOZ3VpmU1  
PlTVjdt4mZ2RPXtrzDMG6ROJqhaYbmka  
=Fyfj  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![glsmyth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@glsmyth](https://www.ruby-forum.com/u/glsmyth)\
**Post date:** [June 18, 2008, 7:41am UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660/6 "2008-06-18T07:41:10Z")

</div>

Jeremy K. wrote:

> On Mon, Jun 16, 2008 at 11:35 PM, George Schreiber  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Any help/hint would be appreciated.
> 
> This only works with a frontend httpd to intercept the X-Sendfile  
> response header and send the actual file.
> 
> Without a frontend httpd, you’re seeing the expected result. Use  
> firebug to verify.

Thanks Jeremy;

- as the filename is correct
- as I have used breakpoints in x\_send\_file and investigated the headers  
it sets  
I think you are right, I am seeing the expected and correct results.

Also, thank you all of you guys; I will go and play with Apache (2.2) –  
the chosen front-end – to see it downloading the complete file.

Best regards,  
George

---

<div class="post-metadata">

**Author:** ![glsmyth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@glsmyth](https://www.ruby-forum.com/u/glsmyth)\
**Post date:** [June 24, 2008, 12:38pm UTC](https://www.ruby-forum.com/t/x-send-file-sends-a-1-byte-file/140660/7 "2008-06-24T12:38:55Z")

</div>

Managed to configure Apache+proxy balancer+XSendFile+Mongrel to work.  
🙂

Thank you guys for putting me on the right track!!
