redirect_to custom http header
On my current project, custom htt开发者_开发百科p header variable need to be set while redirecting for http basic auth. Can I instruct redirect_to for custom headers ?
Thanks.
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. Theheaders
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 toresponse.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
The request
object's headers
method can be used to set custom HTTP headers within a controller:
request.headers['foo'] = 'bar'
精彩评论