简体   繁体   English

如何使Superagent请求标头区分大小写?

[英]How to make superagent request headers case sensitive?

I'm writing a superagent client for a PHP application. 我正在为PHP应用程序编写超级代理客户端。

I'm struggling to get one of the first examples to work: 我正在努力使第一个示例起作用:

.set('X-API-Key', 'foobar')

appears to send headers x-api-key: foobar (and user-agent: node-superagent/1.7.2 ) to server, so I lose the case. 似乎将标头x-api-key: foobar (和user-agent: node-superagent/1.7.2 )发送到服务器,所以我输了。 Is it normal (ie I should make serverside case-insensitive when working with superagent), or am I missing something? 这是正常的吗(即,在使用superagent时应该使服务器端不区分大小写),还是我丢失了什么?

A quick dive into superagent source code shows that there is intentional .toLowerCase call, but it just doesn't seem right, does it? 快速浏览Superagent源代码显示有故意的.toLowerCase调用,但这似乎并不正确,对吗?

OH boy! 好家伙!

I totally missed this: Are HTTP headers case-sensitive? 我完全错过了这一点: HTTP标头区分大小写吗?

The answer is - http headers should not be case sensitive, so sending lowercase is valid, and server-side must take care of it. 答案是-HTTP标头不应区分大小写,因此发送小写字母是有效的,服务器端必须照顾好它。

It is however easy to fall to getallheaders() which returns an assoc array which is case sensitive. 但是,很容易陷入getallheaders() ,该getallheaders()返回区分大小写的assoc数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM