# Setting headers in sent\_file response

**URL:** <https://www.ruby-forum.com/t/setting-headers-in-sent-file-response/119469>\
**Category:** Rails\
**Created:** [November 7, 2007, 8:51am UTC](https://www.ruby-forum.com/t/setting-headers-in-sent-file-response/119469 "2007-11-07T08:51:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [November 7, 2007, 8:51am UTC](https://www.ruby-forum.com/t/setting-headers-in-sent-file-response/119469/1 "2007-11-07T08:51:08Z")

</div>

I’m having trouble playing a video from my site on the iphone using  
send\_file. It seems that I’m missing the Accept-Ranges header in my  
response. How can I set the Accept-Ranges header in my send\_file  
response?

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [November 7, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/setting-headers-in-sent-file-response/119469/2 "2007-11-07T17:12:28Z")

</div>

I actually was able to edit the source of rails to get this  
implemented:

vendor/rails/actionpack/lib/action\_controller/streaming.rb

def send\_file\_headers!(options)  
options.update(DEFAULT\_SEND\_FILE\_OPTIONS.merge(options))  
[:length, :type, :disposition].each do |arg|  
raise ArgumentError, “:#{arg} option required” if  
options[arg].nil?  
end

```
    disposition = options[:disposition].dup || 'attachment'

    disposition <<= %(; filename="#{options[:filename]}") if

```

options[:filename]

```
    headers.update(
      'Content-Length' => options[:length],
      'Content-Type' => options[:type].to_s.strip, #

```

fixes a problem with extra ‘\r’ with some browsers  
‘Content-Disposition’ =\> disposition,  
‘Content-Transfer-Encoding’ =\> ‘binary’  
)

```
    headers.update('Accept-Ranges' => options['Accept-Ranges']) if

```

options[‘Accept-Ranges’]

```
    # Fix a problem with IE 6.0 on opening downloaded files:
    # If Cache-Control: no-cache is set (which Rails does by

```

default),  
# IE removes the file it just downloaded from its cache  
immediately  
# after it displays the “open/save” dialog, which means that  
if you  
# hit “open” the file isn’t there anymore when the application  
that  
# is called for handling the download is run, so let’s  
workaround that  
headers[‘Cache-Control’] = ‘private’ if headers[‘Cache-  
Control’] == ‘no-cache’  
end

And I send my file like this:

send\_file path, :disposition =\> ‘inline’, :type =\> m\_type, ‘Accept-  
Ranges’ =\> ‘bytes’

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [November 16, 2007, 12:43am UTC](https://www.ruby-forum.com/t/setting-headers-in-sent-file-response/119469/3 "2007-11-16T00:43:12Z")

</div>

In retrospect this was dumb because mongrel doesn’t even support byte-  
range requests…
