Last time I wrote an article about “Referrer Policy”. After reading it, a friend asked me: how do you spell the word “Referrer”? Why does it sometimes have two r’s in the middle and sometimes only one?

Yes, this is a very interesting question, and this is for those of you who are confused.

The HTTP Referrer

HTTP has a request header to indicate the source of a page or resource. It was proposed in the 1990s by Philip hallam-baker, who called this request header Referer, and was eventually written into RFC1945, HTTP/1.0:

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. via

Interestingly, he misspelled the word at the time; the correct spelling should have been Referrer. However, before this error was discovered, it had been used a lot. To correct it, all servers and clients need to cooperate with each other, and a lot of code needs to be checked and modified. So HTTP’s standard-setters decided to go with the flow. The following description comes from RFC2616, also known as HTTP/1.1:

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.) via

As you can see, the HTTP/1.1 description is unchanged from HTTP/1.0, except for the addition of an explanation for this error. And that [sic] is Latin for “as it is”. Many other standards refer to HTTP Referer headers with [sic] to avoid misunderstanding.

As such, the HTTP standard-setters are pragmatic and work with what works. Since the HTTP protocol continues to be misspelled, the browser of course has to press the wrong one, and the Server receives the wrong one, so most Web servers, Server languages, or frameworks, follow suit. A few examples:

  • Nginx: Ngx_http_referer_module – used to block access to a site for requests with invalid values in the “Referer” header field; ngx_http_referer_module – used to block access to a site for requests with invalid values in the “Referer” header field;
  • PHP: $_SERVER[‘HTTP_REFERER’] – The address of The page (if any) which referred to The current page;
  • Django: httprequest.meta.HTTP_REFERER — The referring Page, if any;
  • ThinkJS: controller.referer () – Get the referer;

In JavaScript Referrer

The JavaScript mentioned here is for scenarios hosted by the browser, and the referrer attribute obtained is provided by the browser. This time, the browsers were more concerted, adopting the correct spelling and not allowing the error to persist in JavaScript.

For example, document.referrer is defined in DOM Level 2:

Returns the URI [IETF RFC 2396] of the page that linked to this page. The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark). via

The Request interface in the latest Fetch API also has an attribute named referrer:

The referrer attribute’s getter must return the empty string if request’s referrer is no referrer, “about:client” if request’s referrer is client and request’s referrer, serialized, otherwise. via

For more information about the Fetch API, see moonshadow’s great translation of this article: This API is “fascinating” — (the new Fetch API).

Referrer in other standards

Other standards, such as the Referrer Policy, are also written correctly and explicitly not compatible with incorrect spellings, such as in the Delivery via CSP section:

Note: The directive name does not share the HTTP header’s misspelling.

conclusion

Referer in HTTP requests is a classic misspelling that has a long history and can be expected to continue to be wrong, perhaps turning it into a proper noun. So when it comes to reading HTTP headers, we use Referer; Other than that, the correct spelling is usually Referrer.

Originally published on 2015-05-09 17:29:52.

I am the blogger of “JerryQu’s Little Station (imququ.com)”. My independent blog has been suspended for a few years now, and I will bring some useful content to the nuggets community in the near future, as well as write some new articles in nuggets, please follow me.