mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
Merge pull request #253 from boodkb/patch_method
Add support for HTTP PATCH method
This commit is contained in:
commit
7f3f72441c
@ -19,6 +19,7 @@ namespace crow
|
|||||||
CONNECT,
|
CONNECT,
|
||||||
OPTIONS,
|
OPTIONS,
|
||||||
TRACE,
|
TRACE,
|
||||||
|
PATCH = 24,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Delete = 0,
|
Delete = 0,
|
||||||
@ -29,6 +30,7 @@ namespace crow
|
|||||||
Connect,
|
Connect,
|
||||||
Options,
|
Options,
|
||||||
Trace,
|
Trace,
|
||||||
|
Patch = 24,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::string method_name(HTTPMethod method)
|
inline std::string method_name(HTTPMethod method)
|
||||||
@ -51,6 +53,8 @@ namespace crow
|
|||||||
return "OPTIONS";
|
return "OPTIONS";
|
||||||
case HTTPMethod::Trace:
|
case HTTPMethod::Trace:
|
||||||
return "TRACE";
|
return "TRACE";
|
||||||
|
case HTTPMethod::Patch:
|
||||||
|
return "PATCH";
|
||||||
}
|
}
|
||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
@ -132,6 +136,7 @@ constexpr crow::HTTPMethod operator "" _method(const char* str, size_t /*len*/)
|
|||||||
crow::black_magic::is_equ_p(str, "OPTIONS", 7) ? crow::HTTPMethod::Options :
|
crow::black_magic::is_equ_p(str, "OPTIONS", 7) ? crow::HTTPMethod::Options :
|
||||||
crow::black_magic::is_equ_p(str, "CONNECT", 7) ? crow::HTTPMethod::Connect :
|
crow::black_magic::is_equ_p(str, "CONNECT", 7) ? crow::HTTPMethod::Connect :
|
||||||
crow::black_magic::is_equ_p(str, "TRACE", 5) ? crow::HTTPMethod::Trace :
|
crow::black_magic::is_equ_p(str, "TRACE", 5) ? crow::HTTPMethod::Trace :
|
||||||
|
crow::black_magic::is_equ_p(str, "PATCH", 5) ? crow::HTTPMethod::Patch :
|
||||||
throw std::runtime_error("invalid http method");
|
throw std::runtime_error("invalid http method");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -324,6 +324,11 @@ TEST(http_method)
|
|||||||
([](const request& /*req*/){
|
([](const request& /*req*/){
|
||||||
return "post";
|
return "post";
|
||||||
});
|
});
|
||||||
|
CROW_ROUTE(app, "/patch_only")
|
||||||
|
.methods("PATCH"_method)
|
||||||
|
([](const request& /*req*/){
|
||||||
|
return "patch";
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// cannot have multiple handlers for the same url
|
// cannot have multiple handlers for the same url
|
||||||
@ -361,6 +366,17 @@ TEST(http_method)
|
|||||||
ASSERT_EQUAL("get", res.body);
|
ASSERT_EQUAL("get", res.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
request req;
|
||||||
|
response res;
|
||||||
|
|
||||||
|
req.url = "/patch_only";
|
||||||
|
req.method = "PATCH"_method;
|
||||||
|
app.handle(req, res);
|
||||||
|
|
||||||
|
ASSERT_EQUAL("patch", res.body);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
request req;
|
request req;
|
||||||
response res;
|
response res;
|
||||||
|
Loading…
Reference in New Issue
Block a user