X-Requested-With/HTTP_X_REQUESTED_WITH 奇怪的问题
我正在构建一个 Django 网站并尝试使用 request.is_ajax()
函数...但是它只能在本地工作并且正在驱动我疯了!
我正处于刚刚转储标题的位置。 这里(在 django 测试服务器上)有 HTTP_X_REQUESTED_WITH
但在生产服务器(cherokee+scgi)上我得到的只是 X-Requested-With
。
我使用 firebug 来监听发送标头,它是X-Requested-With
(在网站的两个版本上)。 我非常非常困惑。 谁能解释一下发生了什么以及我如何在不失去理智的情况下解决它?
I'm building a Django site and trying to use the request.is_ajax()
function... But it's only working locally and it's driving me crazy!
I'm at the point where I've just dumped the headers. Here (on the django test server) there's HTTP_X_REQUESTED_WITH
but on the production server (cherokee+scgi) all I get is X-Requested-With
.
I've used firebug to snoop the sent headers and it's X-Requested-With
(on both versions of the site). I'm very, very confused. Can anybody explain what's happening and how I can work around it without losing my mind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
wrt/ X-Requested-With => HTTP_X_REQUESTED_WITH东西,它符合CGI规范。 由于 FastCGI、SCGI 和 WSGI 都基于 CGI 规范,Django 开发人员选择遵守此约定(FWIW,ModPythonRequest 类进行相同的重写以保持一致性)。
所以看来你的问题是 cherokee/scgi 链中的某些内容没有正确重写标头。 您使用哪种 scgi 实现?
wrt/ the X-Requested-With => HTTP_X_REQUESTED_WITH stuff, it's in conformance with the CGI specifications. Since FastCGI, SCGI and WSGI are all based on the CGI specs, Django developpers choosed to stick to this convention (FWIW, the ModPythonRequest class do the same rewrite for consistency).
So it seems that your problem is that something in the cherokee/scgi chain doesn't rewrite the headers correctly. Which scgi implemetation are you using ?
我目前正在使用一点中间件来解决这个问题,它本质上是寻找“错误”的标头,如果存在,则附加一个具有相同值的新标头:
但我真的希望我知道这些应该发生什么标头,因为总是发送
X-Requested-With
...我不明白为什么应该将其转换为HTTP_X_REQUESTED_WITH
以及为什么不这样做。编辑:原因似乎是在实际的 Web 服务器内部。
我已经提交了一个错误来添加我的标头,但是所有 X-* 标头都应该转换为 HTTP_X_* 标头吗?
I'm currently working around the issue with a tiny bit of MiddleWare that essentially looks for the "wrong" header and if it exists, appends a new header of the same value:
But I really wish I knew what was supposed to happen with these headers because
X-Requested-With
is always sent... I don't see why that should be translated in toHTTP_X_REQUESTED_WITH
and why it's not.Edit: The cause appears to be deep within the actual web server.
I've filed a bug to get my header added but should all X-* headers be converted into HTTP_X_* headers?