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

How to disable OPTIONS request method? #421

Open
maheshlode opened this issue Sep 12, 2023 · 0 comments
Open

How to disable OPTIONS request method? #421

maheshlode opened this issue Sep 12, 2023 · 0 comments

Comments

@maheshlode
Copy link

I tried using the following code snippet to handle a POST request method in my application, and I want to make sure that it doesn't handle any other request methods. However, when I perform an OPTIONS request, it returns a 204 No Content response status, indicating that it's processing the OPTIONS request. I also attempted to replace POST with OPTIONS, but the code doesn't seem to enter the function. CROW_ROUTE(app, "URL").methods("POST"_method).name("hello")([](const crow::request& req){});

Using CORS

auto &cors = app.get_middleware<crow::CORSHandler>();




// Configure CORS
// clang-format off
cors
 .global()
   .methods("POST"_method, "GET"_method)
 .prefix("/")
   .origin("URL")
   .allow_credentials();
// clang-format on
``
// OPTIONS request handling for "/write"
CROW_ROUTE(app, "/write")
   .methods(crow::HTTPMethod::OPTIONS)
([](const crow::request& req) {
   return crow::response(crow::status::OK);
});

// GET request handling for "/write"
CROW_ROUTE(app, "/write")
   .methods(crow::HTTPMethod::GET)
([](const crow::request& req) {
   CROW_LOG_INFO << "Sending response";
   return crow::response(crow::status::OK, "This is a response");
});`
```
Also I tried using core middleware, but it didn't work as expected. It is not getting inside the OPTIONS method.
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

1 participant