Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Custom response headers

#6260

Setting custom response headers in controller does not work in 3.0.3. For example,

response.headers["Headertitle"]="Headercontent"

gives back standard headers in if you check them from received HTTP response message.

Reported by Xornor · January 7th, 2011 @ 11:26 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Matt Fawcett
    Matt Fawcett

    This works for me in a fresh rails 3.0.3 app:

    Controller

    class PeopleController < ApplicationController
      def index
        response.headers["Headertitle"]="Headercontent"
        render :text => Rails.version
      end
    end
    

    Demo

    curl -i http://localhost:3001/people
    
    HTTP/1.1 200 OK 
    X-Ua-Compatible: IE=Edge
    Etag: "895661fb4afa992a391c33b5534d0f9f"
    Connection: Keep-Alive
    Content-Type: text/html; charset=utf-8
    Headertitle: Headercontent
    Date: Sat, 08 Jan 2011 17:18:23 GMT
    Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10)
    X-Runtime: 0.040454
    Content-Length: 5
    Cache-Control: max-age=0, private, must-revalidate
    
    3.0.3%
    

    January 8th, 2011 @ 05:22 PM

  2. dspencer
    dspencer

    I'm also using rails 3.0.3 and it worked fine for me as well.

    Controller

    class AppController < ApplicationController
      def example
        response.headers["Headertitle"]="Custom Header Content"
        render :text => "Hello, world."
      end
    end
    

    Viewed in Chrome

    Headertitle:Custom Header Content
    

    January 8th, 2011 @ 08:16 PM

  3. Xornor
    Xornor

    Problem disappeared when I started Passenger in the Ruby on rails application directory and used application with it. I am not experienced to deploy Rails applications but I think that before the passenger, the application was executed by Mongrel.

    So, there probably is not bug in Rails?

    January 8th, 2011 @ 08:36 PM

  4. Neeraj Singh
    Neeraj Singh
    • State changed from new to invalid
    • Importance changed from to Low

    January 8th, 2011 @ 11:57 PM