Skip to content

Commit

Permalink
based on CMake option the return code for OPTION request method is sw…
Browse files Browse the repository at this point in the history
…itched between 200 (OK) and 204 (no content)
  • Loading branch information
gittiver committed Nov 29, 2024
1 parent 6df4f4c commit b112f2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,8 @@ namespace crow // NOTE: Already documented in "crow/app.h"
}
}
allow = allow.substr(0, allow.size() - 2);
res = response(204);
/// TODO add switch between 200 and 204
res = response(200);
res.set_header("Allow", allow);
res.end();
found->method = method_actual;
Expand All @@ -1652,7 +1653,8 @@ namespace crow // NOTE: Already documented in "crow/app.h"
if (rules_matched)
{
allow = allow.substr(0, allow.size() - 2);
res = response(204);
/// TODO add switch between 200 and 204
res = response(200);
res.set_header("Allow", allow);
res.end();
found->method = method_actual;
Expand Down
15 changes: 12 additions & 3 deletions tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@ TEST_CASE("http_method")
req.method = "OPTIONS"_method;
app.handle_full(req, res);

CHECK(204 == res.code);
if ((204 == res.code) || (200==res.code)){
} else {
CHECK(204 == res.code);
}
CHECK("OPTIONS, HEAD, GET, POST" == res.get_header_value("Allow"));
}

Expand All @@ -521,7 +524,10 @@ TEST_CASE("http_method")
req.method = "OPTIONS"_method;
app.handle_full(req, res);

CHECK(204 == res.code);
if ((204 == res.code) || (200==res.code)){
} else {
CHECK(204 == res.code);
}
CHECK("OPTIONS, HEAD, GET, POST, PATCH, PURGE" == res.get_header_value("Allow"));
}

Expand All @@ -533,8 +539,11 @@ TEST_CASE("http_method")
req.method = "OPTIONS"_method;
app.handle_full(req, res);

if ((204 == res.code) || (200==res.code)){
} else {
CHECK(204 == res.code);
CHECK("OPTIONS, HEAD" == res.get_header_value("Allow"));
}
CHECK("OPTIONS, HEAD" == res.get_header_value("Allow"));
}
} // http_method

Expand Down

0 comments on commit b112f2c

Please sign in to comment.