Python Flask mod-wsgi自定义标头不在请求中 [英] Python Flask mod-wsgi Custom Headers not in Request

查看:103
本文介绍了Python Flask mod-wsgi自定义标头不在请求中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Python Flask应用程序,由Apache通过mod_wsgi提供.

I've a simple Python Flask application, which is being served by Apache via mod_wsgi.

我的应用程序的一部分可以很好地在我的本地主机上运行,​​但不能通过mod_wsgi进行工作,这是访问自定义请求标头.

The part of my application which works perfectly on my localhost, but does not work through mod_wsgi is the accessing of custom request headers.

当我请求某个网页时,我将其传递给名为auth_user的标头.在我的本地主机上,我可以通过以下方式访问此标头:request.headers["auth_user"],效果很好.但是,当通过Apache和mod_wsgi提供服务时,此自定义标头不存在!打印所有request.headers表示已发送标准Content-TypeCache-Control标头,但没有发送我已经毫无问题地发送到本地主机的auth_user标头.

When I request a certain web page, I pass it a header called auth_user. On my localhost, I am able to access this header as: request.headers["auth_user"], which works great. However when served through Apache and mod_wsgi, this custom header does not exist! Printing all request.headers shows that the standard Content-Type, Cache-Control headers are sent, but not the auth_user header which i've been sending to my localhost with no problem.

Tcpdump显示服务器is接收了标头,但是在我的request.headers中不可用.

Tcpdump shows that the server is receiving the header, but it is not available in my request.headers.

有人知道为什么在应用程序中无法使用此标头吗?

Does anyone have any idea why this header is not being made available within the app?

推荐答案

这个花了我好几个小时...

Well this one took me many hours...

事实证明,仅允许使用字母数字字符或'-'.

Turns out that only alphanumeric characters or '-' are allowed.

任何不符合这些标头的标头都将被忽略.

Any headers not conforming these will be ignored.

http://modwsgi.readthedocs.org/zh_CN/latest/release-notes/version-4.3.0.html <-漏洞修复,第2点.

http://modwsgi.readthedocs.org/en/latest/release-notes/version-4.3.0.html <- Bug fixes, point 2.

这篇关于Python Flask mod-wsgi自定义标头不在请求中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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