aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBooD <bood_kb@mail.ru>2017-10-05 18:13:40 +0300
committerBooD <bood_kb@mail.ru>2017-10-05 18:13:40 +0300
commit8b01385465a2a1366ca2a62a99211140a9c62fa2 (patch)
tree8562a83c1f3a92171aabd4860ac7e4239b42a20b
parent16a0f6b663f69838865a91cdb64cd3e033c636f2 (diff)
downloadcrow-8b01385465a2a1366ca2a62a99211140a9c62fa2.tar.gz
crow-8b01385465a2a1366ca2a62a99211140a9c62fa2.zip
Add HTTP PATCH support
-rw-r--r--include/crow/common.h5
-rw-r--r--tests/unittest.cpp16
2 files changed, 21 insertions, 0 deletions
diff --git a/include/crow/common.h b/include/crow/common.h
index 84d1361..ac6e789 100644
--- a/include/crow/common.h
+++ b/include/crow/common.h
@@ -19,6 +19,7 @@ namespace crow
CONNECT,
OPTIONS,
TRACE,
+ PATCH = 24,
#endif
Delete = 0,
@@ -29,6 +30,7 @@ namespace crow
Connect,
Options,
Trace,
+ Patch = 24,
};
inline std::string method_name(HTTPMethod method)
@@ -51,6 +53,8 @@ namespace crow
return "OPTIONS";
case HTTPMethod::Trace:
return "TRACE";
+ case HTTPMethod::Patch:
+ return "PATCH";
}
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, "CONNECT", 7) ? crow::HTTPMethod::Connect :
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");
}
#endif
diff --git a/tests/unittest.cpp b/tests/unittest.cpp
index 303fa72..bffdd60 100644
--- a/tests/unittest.cpp
+++ b/tests/unittest.cpp
@@ -324,6 +324,11 @@ TEST(http_method)
([](const request& /*req*/){
return "post";
});
+ CROW_ROUTE(app, "/patch_only")
+ .methods("PATCH"_method)
+ ([](const request& /*req*/){
+ return "patch";
+ });
// cannot have multiple handlers for the same url
@@ -365,6 +370,17 @@ TEST(http_method)
request req;
response res;
+ req.url = "/patch_only";
+ req.method = "PATCH"_method;
+ app.handle(req, res);
+
+ ASSERT_EQUAL("patch", res.body);
+ }
+
+ {
+ request req;
+ response res;
+
req.url = "/get_only";
req.method = "POST"_method;
app.handle(req, res);