support HTTP OPTIONS#62
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).