# Looking for fix to content-length = 1 byte with x\_sendfile

**URL:** <https://www.ruby-forum.com/t/looking-for-fix-to-content-length-1-byte-with-x-sendfile/139503>\
**Category:** Rails\
**Created:** [June 4, 2008, 2:41pm UTC](https://www.ruby-forum.com/t/looking-for-fix-to-content-length-1-byte-with-x-sendfile/139503 "2008-06-04T14:41:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aca169/32.png) [@jamie](https://www.ruby-forum.com/u/jamie)\
**Post date:** [June 4, 2008, 2:41pm UTC](https://www.ruby-forum.com/t/looking-for-fix-to-content-length-1-byte-with-x-sendfile/139503/1 "2008-06-04T14:41:31Z")

</div>

I am trying to use sendfile to send files and am using the :x\_sendfile  
=\> true option. I am experiencing problem that the content length of  
any file is truncated to 1 byte. The problem appears to be well  
documented - there is even a fix described here -  
[http://dev.rubyonrails.org/ticket/7643](http://dev.rubyonrails.org/ticket/7643).  
I migrated my app to Rails 2.1 and still the problem exists.

---

<div class="post-metadata">

**Author:** ![jamie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aca169/32.png) [@jamie](https://www.ruby-forum.com/u/jamie)\
**Post date:** [June 13, 2008, 8:23pm UTC](https://www.ruby-forum.com/t/looking-for-fix-to-content-length-1-byte-with-x-sendfile/139503/2 "2008-06-13T20:23:05Z")

</div>

As a (stopgap) solution you can add this code (to an initializer, lib,  
environment.rb):

# Does not allow for manually set Content-Length to be overriden (adds

||= instead of =)

class ActionController::AbstractResponse  
private  
def set\_content\_length!  
self.headers[“Content-Length”] ||= body.size unless  
body.respond\_to?(:call)  
end  
end

This will use any pre-existing Content-Length first if there is one.  
reid
