views:

28

answers:

1

Hello, this has been throwing me off for too long..

Posted below is our Rails 3 controller.

  1. When attempting to access with Internet Explorer the first time, the download prompt fails with a "Unable to download" message.

  2. When attempting to access the same URL immediately following, the download prompt works successfully.

  3. 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.

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.

This appears to be working in all other browsers (firefox, safari, etc).

class StreamingController < ApplicationController

  def index
    respond_to do |wants|
      wants.csv {
        filename = "testing_filename#{DateTime.now}.csv"

        headers.merge!({
          'Cache-Control'             => 'must-revalidate, post-check=0, pre-check=0',
          'Content-Type'              => 'text/csv',
          'Content-Disposition'       => "attachment; filename=\"#{filename}\"",
          'Content-Transfer-Encoding' => '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
A: 

Hi,

This issue could be related to http://support.microsoft.com/kb/316431 - Try to omit "must-validate" in the header "Cache-Control" and see if it works. If not try to omit the header completely. For the "no-cache" part being sent along, is the request possibly going through a proxy that is adding this?

Sven

shendriks
Hello, after spending some time in Rails 3 source, we came to the following conclusions:a) Setting the header that way was not working, we needed to do things like headers["Cache-Control"] = "must-revalidate, post-check=0, pre-check=0"b) Rails 3 will set Cache-Control to the default value of "no-cache" if your response does not properly return a string value. This can be an array of strings, or a single formed string.c) If you previously responded with a proc in Rails 2.x, instead change it to a class that generates a proc, yields strings, and responds to each and all?
releod