aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2017-10-21 21:20:07 +0900
committeripknHama <ipknhama@gmail.com>2017-12-25 15:31:20 +0900
commitdaa1e3eadcfb99bde158a6a9d9455d113b005df5 (patch)
treed73be02abca55b5001c76e9a91b14e9385f5c90e
parent6876a08e61a67592b53a823260203a5e9cd04618 (diff)
downloadcrow-daa1e3eadcfb99bde158a6a9d9455d113b005df5.tar.gz
crow-daa1e3eadcfb99bde158a6a9d9455d113b005df5.zip
Add PURGE method, add a special enum item for counting
-rw-r--r--include/crow/common.h15
-rw-r--r--include/crow/http_parser_merged.h38
-rw-r--r--tests/unittest.cpp16
3 files changed, 48 insertions, 21 deletions
diff --git a/include/crow/common.h b/include/crow/common.h
index ac6e789..f38a3c7 100644
--- a/include/crow/common.h
+++ b/include/crow/common.h
@@ -19,7 +19,8 @@ namespace crow
CONNECT,
OPTIONS,
TRACE,
- PATCH = 24,
+ PATCH,
+ PURGE,
#endif
Delete = 0,
@@ -30,7 +31,12 @@ namespace crow
Connect,
Options,
Trace,
- Patch = 24,
+ Patch,
+ Purge,
+
+
+ InternalMethodCount,
+ // should not add an item below this line: used for array count
};
inline std::string method_name(HTTPMethod method)
@@ -55,6 +61,10 @@ namespace crow
return "TRACE";
case HTTPMethod::Patch:
return "PATCH";
+ case HTTPMethod::Purge:
+ return "PURGE";
+ default:
+ return "invalid";
}
return "invalid";
}
@@ -137,6 +147,7 @@ constexpr crow::HTTPMethod operator "" _method(const char* str, size_t /*len*/)
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 :
+ crow::black_magic::is_equ_p(str, "PURGE", 5) ? crow::HTTPMethod::Purge :
throw std::runtime_error("invalid http method");
}
#endif
diff --git a/include/crow/http_parser_merged.h b/include/crow/http_parser_merged.h
index 2a10252..cf89b05 100644
--- a/include/crow/http_parser_merged.h
+++ b/include/crow/http_parser_merged.h
@@ -96,28 +96,28 @@ typedef int (*http_cb) (http_parser*);
CROW_XX(5, CONNECT, CONNECT) \
CROW_XX(6, OPTIONS, OPTIONS) \
CROW_XX(7, TRACE, TRACE) \
+ /* RFC-5789 */ \
+ CROW_XX(8, PATCH, PATCH) \
+ CROW_XX(9, PURGE, PURGE) \
/* webdav */ \
- CROW_XX(8, COPY, COPY) \
- CROW_XX(9, LOCK, LOCK) \
- CROW_XX(10, MKCOL, MKCOL) \
- CROW_XX(11, MOVE, MOVE) \
- CROW_XX(12, PROPFIND, PROPFIND) \
- CROW_XX(13, PROPPATCH, PROPPATCH) \
- CROW_XX(14, SEARCH, SEARCH) \
- CROW_XX(15, UNLOCK, UNLOCK) \
+ CROW_XX(10, COPY, COPY) \
+ CROW_XX(11, LOCK, LOCK) \
+ CROW_XX(12, MKCOL, MKCOL) \
+ CROW_XX(13, MOVE, MOVE) \
+ CROW_XX(14, PROPFIND, PROPFIND) \
+ CROW_XX(15, PROPPATCH, PROPPATCH) \
+ CROW_XX(16, SEARCH, SEARCH) \
+ CROW_XX(17, UNLOCK, UNLOCK) \
/* subversion */ \
- CROW_XX(16, REPORT, REPORT) \
- CROW_XX(17, MKACTIVITY, MKACTIVITY) \
- CROW_XX(18, CHECKOUT, CHECKOUT) \
- CROW_XX(19, MERGE, MERGE) \
+ CROW_XX(18, REPORT, REPORT) \
+ CROW_XX(19, MKACTIVITY, MKACTIVITY) \
+ CROW_XX(20, CHECKOUT, CHECKOUT) \
+ CROW_XX(21, MERGE, MERGE) \
/* upnp */ \
- CROW_XX(20, MSEARCH, M-SEARCH) \
- CROW_XX(21, NOTIFY, NOTIFY) \
- CROW_XX(22, SUBSCRIBE, SUBSCRIBE) \
- CROW_XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
- /* RFC-5789 */ \
- CROW_XX(24, PATCH, PATCH) \
- CROW_XX(25, PURGE, PURGE) \
+ CROW_XX(22, MSEARCH, M-SEARCH) \
+ CROW_XX(23, NOTIFY, NOTIFY) \
+ CROW_XX(24, SUBSCRIBE, SUBSCRIBE) \
+ CROW_XX(25, UNSUBSCRIBE, UNSUBSCRIBE) \
/* CalDAV */ \
CROW_XX(26, MKCALENDAR, MKCALENDAR) \
diff --git a/tests/unittest.cpp b/tests/unittest.cpp
index 6fe1bbd..e21af39 100644
--- a/tests/unittest.cpp
+++ b/tests/unittest.cpp
@@ -329,6 +329,11 @@ TEST(http_method)
([](const request& /*req*/){
return "patch";
});
+ CROW_ROUTE(app, "/purge_only")
+ .methods("PURGE"_method)
+ ([](const request& /*req*/){
+ return "purge";
+ });
// cannot have multiple handlers for the same url
@@ -381,6 +386,17 @@ TEST(http_method)
request req;
response res;
+ req.url = "/purge_only";
+ req.method = "PURGE"_method;
+ app.handle(req, res);
+
+ ASSERT_EQUAL("purge", res.body);
+ }
+
+ {
+ request req;
+ response res;
+
req.url = "/get_only";
req.method = "POST"_method;
app.handle(req, res);