Skip to content

How to disable OPTIONS request method? #421

@maheshlode

Description

@maheshlode

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions