fetch()发送小写标题键 [英] fetch() sends lower case header keys
问题描述
我正在编写一个用于Atom Electron的HTTP API库。它基于 fetch
。服务器不受我的控制,但是用PHP编写,我可以看到它以区分大小写的方式检查标题。
I'm writing an HTTP API library for use in Atom Electron. It is based on fetch
. The server is outside of my control, but is written in PHP and I can see it checks headers in a case-sensitive fashion.
我的代码类似于:
const headers = new Headers();
headers.append('Authorization', `Bearer ${key}`);
const init = {
method: 'GET',
headers: headers
}
const req = new Request(baseUrl + '/items?format=json');
return fetch(req, init);
请求被 403 FORBIDDEN
拒绝错误。当我在Electron Newtork面板中查看请求时,请求标头已存在,但授权
已成为授权
。
The request is rejected with a 403 FORBIDDEN
error. When I look at the request in the Electron Newtork panel, the request headers are present but Authorization
has become authorization
.
我知道 fetch()
只是遵循HTTP标准,但有一种简单的方法可以获得 fetch()
在我提供时发送标题?
I know fetch()
is just following the HTTP Standard, but is there a simple way to get fetch()
to send the headers as I supply them?
推荐答案
目前获取将 toLowercase()
所有标题。 (这里有一些讨论 https://github.com/whatwg/fetch/issues/304关于可选的禁用)。
Currently fetch will toLowercase()
all headers. (there is some discussion here https://github.com/whatwg/fetch/issues/304 about optional disabling).
现在你可能需要使用 http://api.jquery.com/jquery.ajax/ ,带有标题
选项。
For now you may need to use http://api.jquery.com/jquery.ajax/ with the header
option.
这篇关于fetch()发送小写标题键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!