如何添加自定义 http 标头? [英] How do you add a custom http header?

查看:44
本文介绍了如何添加自定义 http 标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将自定义 http 标头添加到当前托管在 Heroku 上的 Ruby on Rails 应用程序中.

I'm looking to add custom http headers to a Ruby on Rails app that is currently hosted on Heroku.

推荐答案

使用:

response.headers['HEADER NAME'] = 'HEADER VALUE'

在特定方法中或应用程序控制器的 before_filter 方法中,具体取决于您是否需要将其添加到特定响应中或所有响应中.

either in a specific method or to a before_filter method of your application controller depending on whether you need this to be added in a specific or to all of your responses.

正如@BrentMatzelle 在评论中所指出的,对于 Rails 5:

As noted by @BrentMatzelle in the comments, for Rails 5:

response.set_header('HEADER NAME', 'HEADER VALUE')

这篇关于如何添加自定义 http 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆