diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dfe7eaf9..697a53521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,9 @@ option(CROW_BUILD_FUZZER "Instrument and build Crow fuzzer" OFF) option(CROW_AMALGAMATE "Combine all headers into one" OFF) option(CROW_INSTALL "Add install step for Crow" ON ) option(CROW_USE_BOOST "Use Boost.Asio for Crow" OFF) +option( CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST + "Returns HTTP status code OK (200) instead of 204 for OPTIONS request" + OFF ) option(CROW_ENABLE_SSL "Enable Crow's SSL feature for supporting https" OFF) option(CROW_ENABLE_COMPRESSION "Enable Crow's Compression feature for supporting compressed http content" OFF) diff --git a/include/crow/routing.h b/include/crow/routing.h index 279753060..3523b0966 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -1619,7 +1619,12 @@ namespace crow // NOTE: Already documented in "crow/app.h" } } allow = allow.substr(0, allow.size() - 2); - res = response(204); +#ifdef CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST + res = response(crow::status::OK); +#else + res = response(crow::status::NO_CONTENT); +#endif + res.set_header("Allow", allow); res.end(); found->method = method_actual; @@ -1642,8 +1647,12 @@ namespace crow // NOTE: Already documented in "crow/app.h" } if (rules_matched) { +#ifdef CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST + res = response(crow::status::OK); +#else + res = response(crow::status::NO_CONTENT); +#endif allow = allow.substr(0, allow.size() - 2); - res = response(204); res.set_header("Allow", allow); res.end(); found->method = method_actual; diff --git a/tests/unittest.cpp b/tests/unittest.cpp index e78a01384..6543fce2c 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -498,7 +498,11 @@ TEST_CASE("http_method") req.method = "OPTIONS"_method; app.handle_full(req, res); +#ifdef CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST + CHECK(200 == res.code); +#else CHECK(204 == res.code); +#endif CHECK("OPTIONS, HEAD, GET, POST" == res.get_header_value("Allow")); } @@ -521,7 +525,11 @@ TEST_CASE("http_method") req.method = "OPTIONS"_method; app.handle_full(req, res); +#ifdef CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST + CHECK(200 == res.code); +#else CHECK(204 == res.code); +#endif CHECK("OPTIONS, HEAD, GET, POST, PATCH, PURGE" == res.get_header_value("Allow")); } @@ -533,7 +541,11 @@ TEST_CASE("http_method") req.method = "OPTIONS"_method; app.handle_full(req, res); +#ifdef CROW_RETURNS_OK_ON_HTTP_OPTIONS_REQUEST + CHECK(200 == res.code); +#else CHECK(204 == res.code); +#endif CHECK("OPTIONS, HEAD" == res.get_header_value("Allow")); } } // http_method