http 的 referer 请求头为什么少了个字母 r?

查字典发现,没有 referer 这个单词,正确的写法是 referrer。那 http 请求头的 referer 是怎么来的呢?

查阅资料得知:

上世纪 90 年代编写的 RFC1945(HTTP/1.0 协议)第 10.13 章节提出了 Referer 请求头:

The Referer request-header field allows the client to specify, for the server’s benefit, the address (URI) of the resource from which the Request-URI was obtained. This allows a server to generate lists of back-links to resources for interest, logging, optimized caching, etc. It also allows obsolete or mistyped links to be traced for maintenance. The Referer field must not be sent if the Request-URI was obtained from a source that does not have its own URI, such as input from the user keyboard.

意思是:

Referer 请求头字段允许客户端为了服务器的利益指定获取 Request-URI 的资源的地址(URI)。这使得服务器可以为了感兴趣、日志、优化缓存等目的生成资源的反向链接列表。它还允许跟踪过时或打错的链接以进行维护。如果 Request-URI 是从没有自己 URI 的源(例如用户键盘输入)获取的,则不应发送 Referer 字段。

但原本的意思应该是 Referrer,是作者拼写错了。但标准发布后,该请求头被广泛使用,只能将错就错,继续使用错误的拼写。

RFC2616(HTTP/1.1 协议)第 14.36 章节

The Referer[sic] request-header field allows the client to specify, for the server’s benefit, the address (URI) of the resource from which the Request-URI was obtained (the “referrer”, although the header field is misspelled.)

意思是:

Referer 请求头字段允许客户端为了服务器的利益指定获取 Request-URI 的资源的地址(URI)。这使得服务器可以为了感兴趣、日志、优化缓存等目的生成资源的反向链接列表。它还允许跟踪过时或打错的链接以进行维护。(该字段实际拼写错误,应为 Referrer。

可以看到标准里说明了这确实是拼写错误。

但是 JavaScript 的 document.referrer 属性中是拼写正确的,在一些新的 API 接口中也使用了正确的拼写。所以使用过程还是要根据实际情况注意拼写,不是所有地方都使用错误拼写。

参考:

Referrer 还是 Referer? | JerryQu 的小站 (imququ.com)

HTTP Referer 教程 – 阮一峰的网络日志 (ruanyifeng.com)

RFC 1945 – Hypertext Transfer Protocol — HTTP/1.0 (ietf.org)

RFC 2616 – Hypertext Transfer Protocol — HTTP/1.1 (ietf.org)

发表评论