-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parser optimization #332
Merged
Merged
Parser optimization #332
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4cdde73
Optimized HTTP parser
The-EDev 75b1005
Merge branch 'refs/heads/master' into parser_optimization
The-EDev 15908e5
fixed problem with compression test
The-EDev 175b004
code formatting (also disabled formatting where not applicable)
The-EDev ab50fb3
Merge branch 'master' into parser_optimization
The-EDev 9a7677b
Applied changes from review
The-EDev 4e2074d
ran clang-format
The-EDev 9db0e3b
Merge branch 'master' into parser_optimization
The-EDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ | |
|
||
namespace crow | ||
{ | ||
const char cr = '\r'; | ||
const char lf = '\n'; | ||
const std::string crlf("\r\n"); | ||
|
||
enum class HTTPMethod : char | ||
{ | ||
#ifndef DELETE | ||
|
@@ -16,29 +20,148 @@ namespace crow | |
HEAD, | ||
POST, | ||
PUT, | ||
|
||
CONNECT, | ||
OPTIONS, | ||
TRACE, | ||
|
||
PATCH, | ||
PURGE, | ||
|
||
COPY, | ||
LOCK, | ||
MKCOL, | ||
MOVE, | ||
PROPFIND, | ||
PROPPATCH, | ||
SEARCH, | ||
UNLOCK, | ||
BIND, | ||
REBIND, | ||
UNBIND, | ||
ACL, | ||
|
||
REPORT, | ||
MKACTIVITY, | ||
CHECKOUT, | ||
MERGE, | ||
|
||
MSEARCH, | ||
NOTIFY, | ||
SUBSCRIBE, | ||
UNSUBSCRIBE, | ||
|
||
MKCALENDAR, | ||
|
||
LINK, | ||
UNLINK, | ||
|
||
SOURCE, | ||
Comment on lines
+30
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Came from the parser |
||
#endif | ||
|
||
Delete = 0, | ||
Get, | ||
Head, | ||
Post, | ||
Put, | ||
|
||
Connect, | ||
Options, | ||
Trace, | ||
|
||
Patch, | ||
Purge, | ||
|
||
Copy, | ||
Lock, | ||
MkCol, | ||
Move, | ||
Propfind, | ||
Proppatch, | ||
Search, | ||
Unlock, | ||
Bind, | ||
Rebind, | ||
Unbind, | ||
Acl, | ||
|
||
Report, | ||
MkActivity, | ||
Checkout, | ||
Merge, | ||
|
||
MSearch, | ||
Notify, | ||
Subscribe, | ||
Unsubscribe, | ||
|
||
Mkcalendar, | ||
|
||
Link, | ||
Unlink, | ||
|
||
Source, | ||
|
||
|
||
InternalMethodCount, | ||
// should not add an item below this line: used for array count | ||
}; | ||
|
||
const char* method_strings[] = | ||
{ | ||
"DELETE", | ||
"GET", | ||
"HEAD", | ||
"POST", | ||
"PUT", | ||
|
||
"CONNECT", | ||
"OPTIONS", | ||
"TRACE", | ||
|
||
"PATCH", | ||
"PURGE", | ||
|
||
"COPY", | ||
"LOCK", | ||
"MKCOL", | ||
"MOVE", | ||
"PROPFIND", | ||
"PROPPATCH", | ||
"SEARCH", | ||
"UNLOCK", | ||
"BIND", | ||
"REBIND", | ||
"UNBIND", | ||
"ACL", | ||
|
||
"REPORT", | ||
"MKACTIVITY", | ||
"CHECKOUT", | ||
"MERGE", | ||
|
||
"M-SEARCH", | ||
"NOTIFY", | ||
"SUBSCRIBE", | ||
"UNSUBSCRIBE", | ||
|
||
"MKCALENDAR", | ||
|
||
"LINK", | ||
"UNLINK", | ||
|
||
"SOURCE"}; | ||
|
||
|
||
inline std::string method_name(HTTPMethod method) | ||
{ | ||
if (CROW_LIKELY(method < HTTPMethod::InternalMethodCount)) | ||
{ | ||
return method_strings[(unsigned char)method]; | ||
} | ||
return "invalid"; | ||
} | ||
|
||
Comment on lines
+110
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort of inspired by the parser |
||
// clang-format off | ||
|
||
enum status | ||
|
@@ -85,25 +208,6 @@ namespace crow | |
VARIANT_ALSO_NEGOTIATES = 506 | ||
}; | ||
|
||
inline std::string method_name(HTTPMethod method) | ||
{ | ||
switch(method) | ||
{ | ||
case HTTPMethod::Delete: return "DELETE"; | ||
case HTTPMethod::Get: return "GET"; | ||
case HTTPMethod::Head: return "HEAD"; | ||
case HTTPMethod::Post: return "POST"; | ||
case HTTPMethod::Put: return "PUT"; | ||
case HTTPMethod::Connect: return "CONNECT"; | ||
case HTTPMethod::Options: return "OPTIONS"; | ||
case HTTPMethod::Trace: return "TRACE"; | ||
case HTTPMethod::Patch: return "PATCH"; | ||
case HTTPMethod::Purge: return "PURGE"; | ||
default: return "invalid"; | ||
} | ||
return "invalid"; | ||
} | ||
|
||
// clang-format on | ||
|
||
enum class ParamType : char | ||
|
@@ -170,19 +274,52 @@ namespace crow | |
} | ||
} // namespace crow | ||
|
||
// clang-format off | ||
#ifndef CROW_MSVC_WORKAROUND | ||
constexpr crow::HTTPMethod operator"" _method(const char* str, size_t /*len*/) | ||
{ | ||
return crow::black_magic::is_equ_p(str, "GET", 3) ? crow::HTTPMethod::Get : | ||
crow::black_magic::is_equ_p(str, "DELETE", 6) ? crow::HTTPMethod::Delete : | ||
crow::black_magic::is_equ_p(str, "HEAD", 4) ? crow::HTTPMethod::Head : | ||
crow::black_magic::is_equ_p(str, "POST", 4) ? crow::HTTPMethod::Post : | ||
crow::black_magic::is_equ_p(str, "PUT", 3) ? crow::HTTPMethod::Put : | ||
return crow::black_magic::is_equ_p(str, "GET", 3) ? crow::HTTPMethod::Get : | ||
crow::black_magic::is_equ_p(str, "DELETE", 6) ? crow::HTTPMethod::Delete : | ||
crow::black_magic::is_equ_p(str, "HEAD", 4) ? crow::HTTPMethod::Head : | ||
crow::black_magic::is_equ_p(str, "POST", 4) ? crow::HTTPMethod::Post : | ||
crow::black_magic::is_equ_p(str, "PUT", 3) ? crow::HTTPMethod::Put : | ||
|
||
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 : | ||
crow::black_magic::is_equ_p(str, "PURGE", 5) ? crow::HTTPMethod::Purge : | ||
throw std::runtime_error("invalid http method"); | ||
|
||
crow::black_magic::is_equ_p(str, "PATCH", 5) ? crow::HTTPMethod::Patch : | ||
crow::black_magic::is_equ_p(str, "PURGE", 5) ? crow::HTTPMethod::Purge : | ||
crow::black_magic::is_equ_p(str, "COPY", 4) ? crow::HTTPMethod::Copy : | ||
crow::black_magic::is_equ_p(str, "LOCK", 4) ? crow::HTTPMethod::Lock : | ||
crow::black_magic::is_equ_p(str, "MKCOL", 5) ? crow::HTTPMethod::MkCol : | ||
crow::black_magic::is_equ_p(str, "MOVE", 4) ? crow::HTTPMethod::Move : | ||
crow::black_magic::is_equ_p(str, "PROPFIND", 8) ? crow::HTTPMethod::Propfind : | ||
crow::black_magic::is_equ_p(str, "PROPPATCH", 9) ? crow::HTTPMethod::Proppatch : | ||
crow::black_magic::is_equ_p(str, "SEARCH", 6) ? crow::HTTPMethod::Search : | ||
crow::black_magic::is_equ_p(str, "UNLOCK", 6) ? crow::HTTPMethod::Unlock : | ||
crow::black_magic::is_equ_p(str, "BIND", 4) ? crow::HTTPMethod::Bind : | ||
crow::black_magic::is_equ_p(str, "REBIND", 6) ? crow::HTTPMethod::Rebind : | ||
crow::black_magic::is_equ_p(str, "UNBIND", 6) ? crow::HTTPMethod::Unbind : | ||
crow::black_magic::is_equ_p(str, "ACL", 3) ? crow::HTTPMethod::Acl : | ||
|
||
crow::black_magic::is_equ_p(str, "REPORT", 6) ? crow::HTTPMethod::Report : | ||
crow::black_magic::is_equ_p(str, "MKACTIVITY", 10) ? crow::HTTPMethod::MkActivity : | ||
crow::black_magic::is_equ_p(str, "CHECKOUT", 8) ? crow::HTTPMethod::Checkout : | ||
crow::black_magic::is_equ_p(str, "MERGE", 5) ? crow::HTTPMethod::Merge : | ||
|
||
crow::black_magic::is_equ_p(str, "MSEARCH", 7) ? crow::HTTPMethod::MSearch : | ||
crow::black_magic::is_equ_p(str, "NOTIFY", 6) ? crow::HTTPMethod::Notify : | ||
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, "LINK", 4) ? crow::HTTPMethod::Link : | ||
crow::black_magic::is_equ_p(str, "UNLINK", 6) ? crow::HTTPMethod::Unlink : | ||
|
||
crow::black_magic::is_equ_p(str, "SOURCE", 6) ? crow::HTTPMethod::Source : | ||
throw std::runtime_error("invalid http method"); | ||
} | ||
#endif | ||
// clang-format on |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
came from
multipart.h
,connection.h
, and the parser.