2011-06-09 67 views
3

我在后面运行带有PhusionPassenger和NGINX的Rails 3.1。我通过一个简单的HttpClient(OS X的GrahpicalHttpClient)发送请求。我的代码需要在头部有一个令牌和一个ID来验证调用者的真实性。在开发模式中这不是问题,但是一旦我将它移入生产中,头文件变量就会丢失。没有显示。标题变量在生产中丢失

下面是代码:

@caller = Person.check_authentication_token(request.headers['person_id'], request.headers['authentication_token']) 

方法check_authentication_token返回nil如果任一变量是零。正如我所说,这在开发过程中工作正常,但request.headers ['person_id']和request.headers ['authentication_token']都没有生产。有没有其他人看过这个问题?

回答

12

Nginx默认将请求头中的下划线视为无效并随后删除它们,请参阅http://wiki.nginx.org/HttpCoreModule#underscores_in_headers以了解如何解决此问题。

+1

Apache也出现这种情况。 http://stackoverflow.com/questions/22856136/why-underscores-are-forbidden-in-http-header-names – 2016-01-21 16:09:25

+1

拯救了我的生命。我疯了,因为有些头部出现,有些没有(带下划线的头部) – Augusto 2017-01-18 21:41:55

+0

刚刚花了几个小时拉我的头发,试图找出这一个! -.- – aamirl 2017-03-17 08:13:41