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

查看:122
本文介绍了如何添加自定义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在评论中所述, for Rails 5

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

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

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

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