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

OPTIONS still executes methods #30

Closed
mikepc opened this issue Jun 9, 2019 · 4 comments
Closed

OPTIONS still executes methods #30

mikepc opened this issue Jun 9, 2019 · 4 comments

Comments

@mikepc
Copy link

mikepc commented Jun 9, 2019

The OPTIONS preflight request is intended to NOT execute the endpoint, placing this on the endpoint causes the endpoint to be executed on the pre-flight request (so a web client would then double-execute the same endpoint).

The idea of pre-flight is that it's a check to see if the method CAN be executed, not to actually execute it.

@ashleysommer
Copy link
Owner

@mikepc
If you enable automatic_options configurable setting in Sanic-CORS, then the plugin will automatically handle the pre-flight request and return the correct response to the client without executing your route function.

If however you don't use automatic_options, and instead add add the OPTIONS method on your route handler then your route handler will be executed and its up to your code to check if its OPTIONS or not and handle the request appropriately.

I hope that clears things up.

@ashleysommer
Copy link
Owner

@mikepc I'm going to close this Issue. If you have any more problems, please reopen it.

@adamshamsudeen
Copy link

adamshamsudeen commented Jul 11, 2019

Can we add automatic_options to the basic usage example in the docs? That'll make life a lot easier for newcomers.

@ashleysommer
Copy link
Owner

I thought it was already in there.

If it's not, we absolutely should add it.

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

No branches or pull requests

3 participants