Hope documentation includes tutorial & examples on handling CORS for browser OPTIONS preflight requests #2829
Replies: 2 comments 1 reply
-
I am also recently new to webservers and browsers in general, and a few weeks ago, I was also creating a webserver for a web frontend (in another language, though). It also took me a bit of time to get everything with CORS working, especially first finding out what was actually going wrong. On the other hand, asking an AI "how can I handle CORS with the rocket.rs library for rust?" straight gives you the necessary code.. |
Beta Was this translation helpful? Give feedback.
-
There is some work in progress to add better support for handling CORS requests in Rocket. Ideally, we should be able to handle many parts of the OPTIONS request without user intervention, but there is still much work to be done. |
Beta Was this translation helpful? Give feedback.
-
The issue I encountered was related to CORS, but I couldn’t figure out where the problem was coming from. Eventually, I discovered that the problem was due to my middleware handling a custom header that I added, and the browser-generated OPTIONS preflight request obviously could not contain this header. This caused the OPTIONS request to trigger an erroneous response from the middleware, resulting in the actual request not being sent.
Although it seems like a simple matter, I am not an expert on browsers, and it was impossible to know this before finding the cause. This is probably what is referred to as development experience.
If adding a lot of content to the documentation isn’t feasible, I hope it at least mentions that browsers automatically send an OPTIONS request and that middleware should also handle OPTIONS requests.
I’ve reviewed discussions and issues from others, not just in this repository, and none of the solutions mentioned handling of OPTIONS requests by middleware.
Beta Was this translation helpful? Give feedback.
All reactions