This project is archived and is in readonly mode.

#6260 ✓invalid
Xornor

Custom response headers

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

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.

Comments and changes to this ticket

  • Matt Fawcett

    Matt Fawcett January 8th, 2011 @ 05:22 PM

    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%
    
  • dspencer

    dspencer January 8th, 2011 @ 08:16 PM

    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
    
  • Xornor

    Xornor January 8th, 2011 @ 08:36 PM

    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?

  • Neeraj Singh

    Neeraj Singh January 8th, 2011 @ 11:57 PM

    • State changed from “new” to “invalid”
    • Importance changed from “” to “Low”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages