mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 09:18:27 +00:00
Added support for DELETE request body (#418)
* Added support for DELETE request body * Fixed DELETE request body test case typo Co-authored-by: Alexandre Taillefer <alexandre.taillefer@pwc.ca>
This commit is contained in:
parent
1ccddd1b0b
commit
ed8efea98b
2 changed files with 28 additions and 1 deletions
17
httplib.h
17
httplib.h
|
@ -462,6 +462,7 @@ public:
|
|||
Server &Patch(const char *pattern, Handler handler);
|
||||
Server &Patch(const char *pattern, HandlerWithContentReader handler);
|
||||
Server &Delete(const char *pattern, Handler handler);
|
||||
Server &Delete(const char *pattern, HandlerWithContentReader handler);
|
||||
Server &Options(const char *pattern, Handler handler);
|
||||
|
||||
[[deprecated]] bool set_base_dir(const char *dir,
|
||||
|
@ -551,6 +552,7 @@ private:
|
|||
Handlers patch_handlers_;
|
||||
HandlersForContentReader patch_handlers_for_content_reader_;
|
||||
Handlers delete_handlers_;
|
||||
HandlersForContentReader delete_handlers_for_content_reader_;
|
||||
Handlers options_handlers_;
|
||||
Handler error_handler_;
|
||||
Logger logger_;
|
||||
|
@ -2515,7 +2517,7 @@ get_range_offset_and_length(const Request &req, const Response &res,
|
|||
|
||||
inline bool expect_content(const Request &req) {
|
||||
if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" ||
|
||||
req.method == "PRI") {
|
||||
req.method == "PRI" || req.method == "DELETE") {
|
||||
return true;
|
||||
}
|
||||
// TODO: check if Content-Length is set
|
||||
|
@ -2968,6 +2970,13 @@ inline Server &Server::Delete(const char *pattern, Handler handler) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Delete(const char *pattern,
|
||||
HandlerWithContentReader handler) {
|
||||
delete_handlers_for_content_reader_.push_back(
|
||||
std::make_pair(std::regex(pattern), handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Options(const char *pattern, Handler handler) {
|
||||
options_handlers_.push_back(std::make_pair(std::regex(pattern), handler));
|
||||
return *this;
|
||||
|
@ -3481,6 +3490,12 @@ inline bool Server::routing(Request &req, Response &res, Stream &strm) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if (req.method == "DELETE") {
|
||||
if (dispatch_request_for_content_reader(
|
||||
req, res, reader, delete_handlers_for_content_reader_)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read content into `req.body`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue