The default implementation of the render_text method improperly sets @response.headers['Status'] uppercase. The reason it works under webrick is because webrick does a downcase when you access or mutate the headers[key.downcase] hash where the Rails CgiResponse class does not. The Ruby CGI class checks @headers['status'] lowercase and thus fails to pass the proper status on the HTTP/1.x #{status_code} #{status_reason} header line.

The following procedure will allow your rails application to pass the correct HTTP status codes back to your clients through IIS:
  1. Create a new file called #{RAILS_ROOT}/lib/action_controller_base_ext.rb.
  2. Edit the new file, paste in the following code and save it.
module ActionController
  class Base
    def render_text(text = nil, status = nil)
      @performed_render = true
      @response.headers['status'] = (status || DEFAULT_RENDER_STATUS_CODE).to_s
      @response.body = text
    end
  end
end
  1. Edit your #{RAILS_ROOT}/config/environment.rb file and append the following snippet to ensure your application uses the new render_text method instead of the default one.
# Include your app's configuration here:
require 'action_controller_base_ext.rb'

Last edited Jun 4, 2007 at 11:21 PM by bheinz, version 3

Comments

No comments yet.