From be45925731c17bdb9ef7965405e86b9fe247243c Mon Sep 17 00:00:00 2001 From: The-EDev Date: Mon, 21 Mar 2022 13:47:46 +0300 Subject: [PATCH 1/2] fixed issue where parser methods were in all caps --- include/crow/common.h | 6 +-- include/crow/http_parser_merged.h | 76 +++++++++++++++---------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/include/crow/common.h b/include/crow/common.h index 06f25da6a..b6dff1061 100644 --- a/include/crow/common.h +++ b/include/crow/common.h @@ -14,7 +14,7 @@ namespace crow enum class HTTPMethod : char { -#ifndef DELETE +#ifdef THISWILLNOTBEDEFINED DELETE = 0, GET, HEAD, @@ -95,7 +95,7 @@ namespace crow Subscribe, Unsubscribe, - Mkcalendar, + MkCalendar, Link, Unlink, @@ -313,7 +313,7 @@ constexpr crow::HTTPMethod operator"" _method(const char* str, size_t /*len*/) crow::black_magic::is_equ_p(str, "SUBSCRIBE", 9) ? crow::HTTPMethod::Subscribe : crow::black_magic::is_equ_p(str, "UNSUBSCRIBE", 11) ? crow::HTTPMethod::Unsubscribe : - crow::black_magic::is_equ_p(str, "MKCALENDAR", 10) ? crow::HTTPMethod::Mkcalendar : + crow::black_magic::is_equ_p(str, "MKCALENDAR", 10) ? crow::HTTPMethod::MkCalendar : crow::black_magic::is_equ_p(str, "LINK", 4) ? crow::HTTPMethod::Link : crow::black_magic::is_equ_p(str, "UNLINK", 6) ? crow::HTTPMethod::Unlink : diff --git a/include/crow/http_parser_merged.h b/include/crow/http_parser_merged.h index 3fa3e5658..91a235cc9 100644 --- a/include/crow/http_parser_merged.h +++ b/include/crow/http_parser_merged.h @@ -784,21 +784,21 @@ static const int8_t unhex[256] = parser->method = 0; parser->index = 1; switch (ch) { - case 'A': parser->method = (unsigned)HTTPMethod::ACL; break; - case 'B': parser->method = (unsigned)HTTPMethod::BIND; break; - case 'C': parser->method = (unsigned)HTTPMethod::CONNECT; /* or COPY, CHECKOUT */ break; - case 'D': parser->method = (unsigned)HTTPMethod::DELETE; break; - case 'G': parser->method = (unsigned)HTTPMethod::GET; break; - case 'H': parser->method = (unsigned)HTTPMethod::HEAD; break; - case 'L': parser->method = (unsigned)HTTPMethod::LOCK; /* or LINK */ break; - case 'M': parser->method = (unsigned)HTTPMethod::MKCOL; /* or MOVE, MKACTIVITY, MERGE, M-SEARCH, MKCALENDAR */ break; - case 'N': parser->method = (unsigned)HTTPMethod::NOTIFY; break; - case 'O': parser->method = (unsigned)HTTPMethod::OPTIONS; break; - case 'P': parser->method = (unsigned)HTTPMethod::POST; /* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */ break; - case 'R': parser->method = (unsigned)HTTPMethod::REPORT; /* or REBIND */ break; - case 'S': parser->method = (unsigned)HTTPMethod::SUBSCRIBE; /* or SEARCH, SOURCE */ break; - case 'T': parser->method = (unsigned)HTTPMethod::TRACE; break; - case 'U': parser->method = (unsigned)HTTPMethod::UNLOCK; /* or UNSUBSCRIBE, UNBIND, UNLINK */ break; + case 'A': parser->method = (unsigned)HTTPMethod::Acl; break; + case 'B': parser->method = (unsigned)HTTPMethod::Bind; break; + case 'C': parser->method = (unsigned)HTTPMethod::Connect; /* or COPY, CHECKOUT */ break; + case 'D': parser->method = (unsigned)HTTPMethod::Delete; break; + case 'G': parser->method = (unsigned)HTTPMethod::Get; break; + case 'H': parser->method = (unsigned)HTTPMethod::Head; break; + case 'L': parser->method = (unsigned)HTTPMethod::Lock; /* or LINK */ break; + case 'M': parser->method = (unsigned)HTTPMethod::MkCol; /* or MOVE, MKACTIVITY, MERGE, M-SEARCH, MKCALENDAR */ break; + case 'N': parser->method = (unsigned)HTTPMethod::Notify; break; + case 'O': parser->method = (unsigned)HTTPMethod::Options; break; + case 'P': parser->method = (unsigned)HTTPMethod::Post; /* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */ break; + case 'R': parser->method = (unsigned)HTTPMethod::Report; /* or REBIND */ break; + case 'S': parser->method = (unsigned)HTTPMethod::Subscribe; /* or SEARCH, SOURCE */ break; + case 'T': parser->method = (unsigned)HTTPMethod::Trace; break; + case 'U': parser->method = (unsigned)HTTPMethod::Unlock; /* or UNSUBSCRIBE, UNBIND, UNLINK */ break; default: CROW_SET_ERRNO(CHPE_INVALID_METHOD); goto error; @@ -830,25 +830,25 @@ static const int8_t unhex[256] = case ((unsigned)HTTPMethod::meth << 16 | pos << 8 | ch): \ parser->method = (unsigned)HTTPMethod::new_meth; break; - CROW_XX(POST, 1, 'U', PUT) - CROW_XX(POST, 1, 'A', PATCH) - CROW_XX(POST, 1, 'R', PROPFIND) - CROW_XX(PUT, 2, 'R', PURGE) - CROW_XX(CONNECT, 1, 'H', CHECKOUT) - CROW_XX(CONNECT, 2, 'P', COPY) - CROW_XX(MKCOL, 1, 'O', MOVE) - CROW_XX(MKCOL, 1, 'E', MERGE) - CROW_XX(MKCOL, 1, '-', MSEARCH) - CROW_XX(MKCOL, 2, 'A', MKACTIVITY) - CROW_XX(MKCOL, 3, 'A', MKCALENDAR) - CROW_XX(SUBSCRIBE, 1, 'E', SEARCH) - CROW_XX(SUBSCRIBE, 1, 'O', SOURCE) - CROW_XX(REPORT, 2, 'B', REBIND) - CROW_XX(PROPFIND, 4, 'P', PROPPATCH) - CROW_XX(LOCK, 1, 'I', LINK) - CROW_XX(UNLOCK, 2, 'S', UNSUBSCRIBE) - CROW_XX(UNLOCK, 2, 'B', UNBIND) - CROW_XX(UNLOCK, 3, 'I', UNLINK) + CROW_XX(Post, 1, 'U', Put) + CROW_XX(Post, 1, 'A', Patch) + CROW_XX(Post, 1, 'R', Propfind) + CROW_XX(Put, 2, 'R', Purge) + CROW_XX(Connect, 1, 'H', Checkout) + CROW_XX(Connect, 2, 'P', Copy) + CROW_XX(MkCol, 1, 'O', Move) + CROW_XX(MkCol, 1, 'E', Merge) + CROW_XX(MkCol, 1, '-', MSearch) + CROW_XX(MkCol, 2, 'A', MkActivity) + CROW_XX(MkCol, 3, 'A', MkCalendar) + CROW_XX(Subscribe, 1, 'E', Search) + CROW_XX(Subscribe, 1, 'O', Source) + CROW_XX(Report, 2, 'B', Rebind) + CROW_XX(Propfind, 4, 'P', Proppatch) + CROW_XX(Lock, 1, 'I', Link) + CROW_XX(Unlock, 2, 'S', Unsubscribe) + CROW_XX(Unlock, 2, 'B', Unbind) + CROW_XX(Unlock, 3, 'I', Unlink) #undef CROW_XX default: CROW_SET_ERRNO(CHPE_INVALID_METHOD); @@ -869,7 +869,7 @@ static const int8_t unhex[256] = CROW_MARK(url); CROW_MARK(url_start); - if (parser->method == (unsigned)HTTPMethod::CONNECT) { + if (parser->method == (unsigned)HTTPMethod::Connect) { parser->state = s_req_server_start; } @@ -918,7 +918,7 @@ static const int8_t unhex[256] = break; case cr: // No space after URL means no HTTP version. Which means the request is using HTTP/0.9 case lf: - if (CROW_UNLIKELY(parser->method != (unsigned)HTTPMethod::GET)) // HTTP/0.9 doesn't define any method other than GET + if (CROW_UNLIKELY(parser->method != (unsigned)HTTPMethod::Get)) // HTTP/0.9 doesn't define any method other than GET { parser->state = s_dead; CROW_SET_ERRNO(CHPE_INVALID_VERSION); @@ -949,7 +949,7 @@ static const int8_t unhex[256] = parser->state = s_req_http_H; break; case 'I': - if (parser->method == (unsigned)HTTPMethod::SOURCE) { + if (parser->method == (unsigned)HTTPMethod::Source) { parser->state = s_req_http_I; break; } @@ -1603,7 +1603,7 @@ static const int8_t unhex[256] = /* Set this here so that on_headers_complete() callbacks can see it */ parser->upgrade = - (parser->flags & F_UPGRADE || parser->method == (unsigned)HTTPMethod::CONNECT); + (parser->flags & F_UPGRADE || parser->method == (unsigned)HTTPMethod::Connect); /* Here we call the headers_complete callback. This is somewhat * different than other callbacks because if the user returns 1, we From c199fa08dc7098fc4a80d3960cc39eb94b8e2ab9 Mon Sep 17 00:00:00 2001 From: Farook Al-Sammarraie Date: Mon, 21 Mar 2022 13:57:13 +0300 Subject: [PATCH 2/2] removed test changes --- include/crow/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/crow/common.h b/include/crow/common.h index 234bffca3..2e9280022 100644 --- a/include/crow/common.h +++ b/include/crow/common.h @@ -14,7 +14,7 @@ namespace crow enum class HTTPMethod : char { -#ifdef THISWILLNOTBEDEFINED +#ifndef DELETE DELETE = 0, GET, HEAD,