# Missing Content-Length header with lighttpd

**URL:** <https://www.ruby-forum.com/t/missing-content-length-header-with-lighttpd/64486>\
**Category:** Rails\
**Created:** [June 26, 2006, 11:43am UTC](https://www.ruby-forum.com/t/missing-content-length-header-with-lighttpd/64486 "2006-06-26T11:43:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![klex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@klex](https://www.ruby-forum.com/u/klex)\
**Post date:** [June 26, 2006, 11:43am UTC](https://www.ruby-forum.com/t/missing-content-length-header-with-lighttpd/64486/1 "2006-06-26T11:43:22Z")

</div>

We have our rails application running using lighttpd and everything  
seems fine with Firefox, but when the client is Explorer some media  
doesn’t get transferred from the server correctly. With Webrick,  
Content-Length is set when a request is made for an mp3 file. Using  
Firefox with lighttpd, Transfer-Encoding is set to chunked, so the  
Content-Length field isn’t required. With IE, however, neither  
Content-Length nor Transfer-Encoding is set.

For straight-forward downloads that isn’t a problem (?), but I want the  
content to be played by a Flash mp3 player, and as it stands right now  
the player doesn’t seem to be receiving the mp3 – and I’m pretty sure  
that’s because the response header is missing both Content-Length and  
Transfer-Encoding fields. There’s a very nice blog entry on this problem  
at: [http://www.purpletech.com/blog/?itemid=43](http://www.purpletech.com/blog/?itemid=43) , but adding the suggested  
after\_filter to my application controller didn’t make a difference – I  
assume either Rails or Lighttpd is over-riding my header settings.

Does anybody have any clues as to how I can get the response header to  
include either Content-Length or Transfer-Encoding: chunked? Any advice  
greatly appreciated.

Alexis

– Response headers are as follows:

Firefox:

HTTP/1.1 200 OK  
Date: Mon, 26 Jun 2006 09:23:59 GMT  
Server: lighttpd/1.4.10  
Content-Type: audio/mpeg  
Set-Cookie: \_session\_id=640a71da388d5b1b9722cd8a4bb4da1b; path=/  
Content-Transfer-Encoding: binary  
Cache-Control: private  
Content-Disposition: attachment; filename=“testing.mp3”  
Connection: close  
Transfer-Encoding: chunked

IE:

HTTP/1.1 200 OK  
Date: Mon, 26 Jun 2006 09:23:31 GMT  
Server: lighttpd/1.4.10  
Content-Type: audio/mpeg  
Set-Cookie: \_session\_id=12ac3d5b185fc60936d8d5e82459394a; path=/  
Content-Transfer-Encoding: binary  
Cache-Control: private  
Content-Disposition: attachment; filename=“testing.mp3”  
Connection: close

---

<div class="post-metadata">

**Author:** ![klex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@klex](https://www.ruby-forum.com/u/klex)\
**Post date:** [June 27, 2006, 4:26am UTC](https://www.ruby-forum.com/t/missing-content-length-header-with-lighttpd/64486/2 "2006-06-27T04:26:50Z")

</div>

So has nobody else had any problems with lighttpd and content-length  
headers not being set? Given that the lighttpd/fcgi combo seems to be  
the setup of choice, that would seem bizarre to me. The Rails wiki  
seems to recognize the problem – from  
[http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles](http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles)

> This stuff wonâ??t work in lighttpd due to a bug in lighttpd and file uploads.  
> That was many versions ago, however. It may work now.

Ignoring send\_file or send\_data and setting the headers/writing the body  
myself, I can seem to set just about every single header except  
Content-Length – whatever I put in Content-Length gets completely  
ignored. The only way I can get anything put in Content-Length is  
actually if I set it (to anything) while simultaneously (and illegally)  
setting Transfer-Encoding to chunked. In this case, Content-Length is  
output as zero, which is useless anyway.

Is it time to start looking into Mongrel?

Alexis

---

<div class="post-metadata">

**Author:** ![klex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@klex](https://www.ruby-forum.com/u/klex)\
**Post date:** [June 27, 2006, 4:34am UTC](https://www.ruby-forum.com/t/missing-content-length-header-with-lighttpd/64486/3 "2006-06-27T04:34:28Z")

</div>

On Tue, 2006-06-27 at 04:26 +0200, Alexis Glass wrote:

> myself, I can seem to set just about every single header except  
> Content-Length – whatever I put in Content-Length gets completely  
> ignored. The only way I can get anything put in Content-Length is  
> actually if I set it (to anything) while simultaneously (and illegally)  
> setting Transfer-Encoding to chunked. In this case, Content-Length is  
> output as zero, which is useless anyway.
> 
> Is it time to start looking into Mongrel?

Try out the X-Sendfile header, it might work better if you just want  
rails to hand lighty a file. After that try using webrick and then  
mongrel directly and see if you can get the content-length. If you  
don’t then you’re doing it wrong. If you do then lighty is doing it  
wrong.

–  
Zed A. Shaw

> **[Zed A. shaw](https://zedshaw.com/)**
>
> Personal essays and writings by Zed A. Shaw.

[http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![klex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@klex](https://www.ruby-forum.com/u/klex)\
**Post date:** [June 27, 2006, 8:24am UTC](https://www.ruby-forum.com/t/missing-content-length-header-with-lighttpd/64486/4 "2006-06-27T08:24:30Z")

</div>

Zed S. wrote:

> Try out the X-Sendfile header, it might work better if you just want  
> rails to hand lighty a file. After that try using webrick and then  
> mongrel directly and see if you can get the content-length. If you  
> don’t then you’re doing it wrong. If you do then lighty is doing it  
> wrong.

Thanks a lot for the suggestion. I can’t seem to get the x-sendfile  
header to do anything, but regardless even if I enter the path directly  
into the browser (which I assume using the x-sendfile header would be  
equivalent to) it seems that lighttpd is insisting on using a chunked  
transfer-encoding instead of setting the content-length (as I would like  
it to). I haven’t trie Mongrel yet, but Webrick seems perfectly happy to  
let me set the content length. I guess I’ll have to look into  
lighttpd’s documentation a bit more, but I suppose in the worst case  
scenario perhaps we could set apache up to serve the files (grumble).

Thanks again for the help.

Alexis

---

<div class="post-metadata">

**Author:** ![klex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@klex](https://www.ruby-forum.com/u/klex)\
**Post date:** [June 27, 2006, 11:38am UTC](https://www.ruby-forum.com/t/missing-content-length-header-with-lighttpd/64486/5 "2006-06-27T11:38:40Z")

</div>

I guess I should have mentioned that lighttpd was behind apache 2.0.40  
and being accessed by mod\_proxy via ProxyPass. It looks like lighttpd  
isn’t doing anything wrong after all - but that mod\_proxy is just  
stripping Content-Length from the headers. Will update to Apache 2.0.55  
with fingers crossed.

Alexis
