title: CSV download fails with Internet Explorer on first attempt, works on subsequent attempts
body: <p>this has been throwing me off for too long..</p>
  
  <p>Posted below is our Rails 3 controller.</p>
  
  <ol>
  <li><p>When attempting to access with Internet Explorer the first time, the download prompt fails with a "Unable to download" message.</p></li>
  <li><p>When attempting to access the same URL immediately following, the download prompt works successfully. </p></li>
  <li><p>In any instance, the Cache-Control header is not being sent properly either. We are providing a specific value to the Rack Response, yet the Cache-Control is always being returned as "Cache-Control: no-cache". The other header values provided are being sent correctly though. This may be a separate question, but throwing me off regardless.</p></li>
  </ol>
  
  <p>The sample below is a mock of how our actual system works with client data. A CSV is started and streamed to the client. The download is progressive, to avoid a long wait time while the CSV generation is complete. These files can be upwards of 20-30mb, so waiting a few minutes before a download starts is not desirable.</p>
  
  <p>This appears to be working in all other browsers (firefox, safari, etc).</p>
  
  <pre><code>class StreamingController &lt; ApplicationController
  
    def index
      respond_to do |wants|
        wants.csv {
          filename = "testing_filename#{DateTime.now}.csv"
  
          headers.merge!({
            'Cache-Control'             =&gt; 'must-revalidate, post-check=0, pre-check=0',
            'Content-Type'              =&gt; 'text/csv',
            'Content-Disposition'       =&gt; "attachment; filename=\"#{filename}\"",
            'Content-Transfer-Encoding' =&gt; 'binary'
          })
  
          responder = Rack::Response.new([], 200, headers) do |response|
            response.finish do |r|
              100000.times do |t|
                r.write(t)
              end
            end
          end
  
          self.response_body = responder
        }
      end
    end
  end
  </code></pre>