Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect_to custom http header

On my current project, custom http header variable need to be set while redirecting for http basic auth. Can I instruct redirect_to for custom headers ?

Thanks.

like image 430
Alexandre Mazari Avatar asked Jun 14 '10 10:06

Alexandre Mazari


1 Answers

Rails allows you to add custom headers while redirecting. It is discussed in Rails guides.

10.2.1 Setting Custom Headers

If you want to set custom headers for a response then response.headers is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them automatically. If you want to add or change a header, just assign it to response.headers

So your action code would end up being something like this:

def some_action
  # do_some_work

  response.headers["your-key"] = "some value"
  redirect_to url
end
like image 157
Uzbekjon Avatar answered Oct 24 '22 08:10

Uzbekjon