Skip to content

Commit

Permalink
Add PURGE method, add a special enum item for counting
Browse files Browse the repository at this point in the history
  • Loading branch information
ipkn committed Dec 25, 2017
1 parent 6876a08 commit daa1e3e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
15 changes: 13 additions & 2 deletions include/crow/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace crow
CONNECT,
OPTIONS,
TRACE,
PATCH = 24,
PATCH,
PURGE,
#endif

Delete = 0,
Expand All @@ -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)
Expand All @@ -55,6 +61,10 @@ namespace crow
return "TRACE";
case HTTPMethod::Patch:
return "PATCH";
case HTTPMethod::Purge:
return "PURGE";
default:
return "invalid";
}
return "invalid";
}
Expand Down Expand Up @@ -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
38 changes: 19 additions & 19 deletions include/crow/http_parser_merged.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \

Expand Down
16 changes: 16 additions & 0 deletions tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -377,6 +382,17 @@ TEST(http_method)
ASSERT_EQUAL("patch", res.body);
}

{
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;
Expand Down

0 comments on commit daa1e3e

Please sign in to comment.