W3C 是否指定 XMLHttpRequest 可以设置哪些 HTTP header ?如果是这样,他们是否出于安全原因发布了证明这些要求合理的文件?
是否由浏览器自行决定限制 HTTP header ?如果是这样,是否有一个文档或一组在线文档列出了不同 XHR 实现的怪癖,或者是否有必要在每个实现的文档中找到该信息?
最佳答案
W3C 有 this spec关于 setRequestHeader
Terminate these steps if header is a case-insensitive match for one of the following headers:
- Accept-Charset
- Accept-Encoding
- Access-Control-Request-Headers
- Access-Control-Request-Method
- Connection
- Content-Length
- Cookie
- Cookie2
- Content-Transfer-Encoding
- Date
- Expect
- Host
- Keep-Alive
- Origin
- Referer
- TE
- Trailer
- Transfer-Encoding
- Upgrade
- User-Agent
- Via
… or if the start of header is a case-insensitive match for Proxy- or Sec- (including when header is just Proxy- or Sec-).
The above headers are controlled by the user agent to let it control those aspects of transport. This guarantees data integrity to some extent. Header names starting with Sec- are not allowed to be set to allow new headers to be minted that are guaranteed not to come from XMLHttpRequest.
你也可以考虑:
如果 header 不在 author-request-headers 中list 将 header 及其关联值附加到列表中并终止这些步骤。
关于浏览器的实现,我发现了这个很好的测试:https://dvcs.w3.org/hg/webapps/diff/5814514eeba4/tests/XMLHttpRequest/setrequestheader-header-forbidden.htm你不能用它来找到当前的差异。
例如,IE 对 header 的安全性定义如下:
IE : 引用RFC2616, Section 14 :标准标题的一般列表的标题字段定义。服务器最终负责遵守请求的 header 。到目前为止,最常见的请求 header 是 Content-Type,某些 XML Web 服务需要它。
关于javascript - JavaScript 可以设置哪些 HTTP header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11876145/