开发者

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. 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


The request object's headers method can be used to set custom HTTP headers within a controller:

request.headers['foo'] = 'bar'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜