New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured parsing of the Origin header (issue #2007) #2082

merged 2 commits into from Sep 13, 2018


None yet
4 participants

davegurnell commented Sep 13, 2018

This PR improves the parsing of the Origin header. It's joint work with @hosamaly at Syntactic Sugar, London.

Instead of being interpreted as a string, the header is now interpreted as a list of items of type Origin.Host. These are similar to Uris except that Origin only permits a scheme, host, and port.

We commonly think of the Origin as containing a single host. According to the Mozilla Developer page, however, the header may be an empty string ( And according to the RFC, it may contain multiple hosts (

There's one last complication. The RFC technically states that Origin may be the literal string null, which translates to an "opaque origin" ()

Structured parsing of Origin headers.
Work done in conjunction with Hosam Aly (@hosamaly) at Syntactic Sugar, London.

Instead of being interpreted as a string, the Origin header is now interpreted
as a "null" header or a non-empty list of "hosts" as specified in the RFC:

Note that we don't use `Uri` to model the hosts because the RFC states that
only a scheme, host, and port are acceptable.

The following MDN article is the first hit on Google.
It states that the empty string is a valid Origin header.
While this is technically incorrect,
we do permissively parse the empty string as a null header:

This PR also updates some tests in CORSSpec
that erroneously added a trailing slash to headers in their test data.

This looks good. Run it though scalafmt and the build will succeed.


This comment has been minimized.


davegurnell commented Sep 13, 2018

Ah! Thanks for the tip. Rerunning...


aeons approved these changes Sep 13, 2018


Looks great. Thanks!

@aeons aeons merged commit a37e813 into http4s:master Sep 13, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment