-
Notifications
You must be signed in to change notification settings - Fork 2.4k
support HTTP OPTIONS #62
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
Conversation
@adikabintang, thanks for the PR. Yes, it would be nice to support OPTIONS, so that we could handle the HTTP preflight request. After I took a look at your code and pondered over how the OPTIONS support could be implemented, I now think it would be better to provide svr.options(R"(\*)", [](const auto& req, auto& res) {
res.set_header("Allow", "GET, POST, HEAD, OPTIONS");
});
svr.options("/resource/foo", [](const auto& req, auto& res) {
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin").c_str());
res.set_header("Allow", "GET, POST, HEAD, OPTIONS");
res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization");
res.set_header("Access-Control-Allow-Methods", "OPTIONS, GET, POST, HEAD");
}); When I have time, I'll try to implement the above idea. Thanks again for your valuable feedback! |
@yhirose This feature would be very useful and I can see that you have a new branch (branch issue-57) to support this. Thank you very much for your work. |
@adikabintang, I have just merged the branch. I changed HTTP verb method names to be the initial caps such as svr.Options(R"(\*)", [](const auto& req, auto& res) {
res.set_header("Allow", "GET, POST, HEAD, OPTIONS");
});
svr.Options("/resource/foo", [](const auto& req, auto& res) {
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin").c_str());
res.set_header("Allow", "GET, POST, HEAD, OPTIONS");
res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization");
res.set_header("Access-Control-Allow-Methods", "OPTIONS, GET, POST, HEAD");
}); Hope this fix will solve your problem! |
Wow, thank you @yhirose |
Support for HTTP OPTIONS. Useful for Cross-Origin Resource Sharing (CORS).