一点想法,不一定对:
Q:为什么要有 `Origin`?
A:
https://fetch.spec.whatwg.org/#origin-header> The `Origin` header is a version of the `Referer` [sic] header that does not reveal a path.
通过不同 Referrer Policy 可以精准控制 `Origin` 和 `Referrer` 的发送
Q:为什么要有 `Referer`?
A:
https://httpwg.org/specs/rfc7231.html#header.referer> The "Referer" [sic] header field allows the user agent to specify a URI reference for the resource from which the target URI was obtained (i.e., the "referrer", though the field name is misspelled).
`Referer`(以及 `Origin`)作为重要的来源信息是默认发送的,此时尚不考虑跨域。
“非跨域请求时 HTTP 请求头有时候也会带上 Origin 头字段”实际上是默认行为,应该问的是“为什么有的时候不会带 Origin/Referer”,对此问题不同上下文有不同回答(见
https://www.w3.org/TR/referrer-policy/ 里“Integration with Fetch/HTML/CSS”),一句话概括大概就是“except in cases where the origin information would be sensitive or unnecessary.” (
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin#description)。