Custom response headers

I have to change all headers in Ruby on rails response message. This
must be done because my application should read another www-page from
the other server and then send it to the client such as it comes from
the original web server.

I thought first that it is easy to change headers in class
ApplicationController < ActionController::Base by creating after
filter following way:

class ApplicationController < ActionController::Base
   after_filter :customheaders

private

   def customheaders
      response.headers["Test header title"]="Test header value"
   end
end

However, my application sends always just default headers. I know that
the after filter works because if I change body content in
customheaders -function, it works (response.body = "New body
content").

The application renders web page normally in a view-component. Rails
version is 3.0.3.

Would anyone know how I could change all headers of the response
message in application controller?

That looks like it should work (I don't think that an after filter is
'too late' to set headers). How are you testing that the headers
aren't there?

Fred

That looks like it should work (I don't think that an after filter is
'too late' to set headers). How are you testing that the headers
aren't there?

Fred

I checked headers with two separate methods, by sending HTTP request
with curl and -i option and also with Firefox Live HTTP headers -
addon.

I also tried to set custom headers in original controller component
(no filters), but results were same.

Are you doing this at localhost, or in production behind a "real" Web server?

Walter

Curl was used in the same server (Ubuntu) as application is executed.
Firefox was running in the another computer.

I made changes directly to the application which was running in the
server. The server is in "production".

Curl was used in the same server (Ubuntu) as application is executed.
Firefox was running in the another computer.

I made changes directly to the application which was running in the
server. The server is in “production”.

Dumb question: are you sure your changes are actually in use (ie whatever needs to be restarted has been restarted)? Can you replicate this on your development machine?

Fred

Dumb question: are you sure your changes are actually in use (ie whatever needs to be restarted has been restarted)? Can you replicate this on your development machine?

All other changes come in use as I expect? What could not be in use?

I tried to debug content of the response object and oddly if I render
it at the end of the view component ( <%= debug response %>), header
content is fine. It is exactly such as I expect. But when I check
headers of the received HTTP message, they are different than in
response object?

Could this problem happen because I get unauthorized message from the
original server and I try to use headers of it in normal Ruby on rails
response message?

body: !str
  str: ""
  "@_rails_html_safe": false
body_exist: true
code: "401"
header:
  content-language:
  - en-US
  content-type:
  - text/plain
  connection:
  - close
  server:
  - IBM_HTTP_Server
  date:
  - Fri, 07 Jan 2011 09:13:26 GMT
  content-length:
  - "0"
http_version: "1.1"
message: Unauthorized
read: true
socket: