cocos-creator-packages / adapters

25 stars 43 forks source link

XMLHttpRequest#getResponseHeader should be case insensitive #190

Open leeyeh opened 4 years ago

leeyeh commented 4 years ago

The search for the header name is case-insensitive.

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getResponseHeader

当前的实现没有忽略大小写:

https://github.com/cocos-creator-packages/adapters/blob/ff6ddfb8e0fbdb07d82750cfd7f5cfbd0864e64a/platforms/wechat/wrapper/builtin/XMLHttpRequest.js#L77

这意味着如果 server 返回的是 Content-Type: application/json,而代码中使用 xhr.getResponseHeader('content-type') 拿到的会是 undefined。比如我们用的 superagent 就是这么用的: https://github.com/visionmedia/superagent/blob/aa43b3d27594d231afee9009ae740ce1b44a6f62/src/client.js#L351

请考虑在实现 getResponseHeader 时忽略 key 的大小写。感谢支持。

PPpro commented 4 years ago

感谢反馈,我们之后跟标准同步一下