Skip to content
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

Improve API endpoint compatibility by preventing CORS preflight request. #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richardkmichael
Copy link
Contributor

The Content-Type and Referrer headers cause browsers implementing
CORS to send a preflight (OPTION) request. If we remove them, our
GET requests will be "simple", and no longer trigger a preflight.

Preventing the preflight and using a "simple" request makes it easier to
work with endpoints that do not implement an OPTIONS response, but
nevertheless do set Access-Control-Allow-Origin on the GET response.
(Especially development environments.)

We do not need Content-Type because our GET requests have no
payload.

Users requiring Referrer may add it explicitly with <autocomplete :request-headers="...">.

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy

Tested on latest Chrome, Firefox and Safari. Should be fine back to
June/July 2016 (Chrome 52, Firefox 47). Note, the MDN browser compat
info for Request.referrerPolicy Safari seems incomplete: refererPolicy
does work.

The `Content-Type` and `Referrer` headers cause browsers implementing
CORS to send a preflight (`OPTION`) request. If we remove them, our
`GET` requests will be "simple", and no longer trigger a preflight.

Preventing the preflight and using a "simple" request makes it easier to
work with endpoints that do not implement an `OPTIONS` response, but
nevertheless do set `Access-Control-Allow-Origin` on the `GET` response.
(Especially development environments.)

We do not need `Content-Type` because our `GET` requests have no
payload.

Users requiring `Referrer` may add it explicitly with `<autocomplete
:request-headers="...">`.

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
https://developer.mozilla.org/en-US/docs/Web/API/Request/referrerPolicy

Tested on latest Chrome, Firefox and Safari. Should be fine back to
June/July 2016 (Chrome 52, Firefox 47).  Note, the MDN browser compat
info for Request.referrerPolicy Safari seems incomplete: refererPolicy
does work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant