Skip to content

Commit

Permalink
DQUOTE is not a valid field name char
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Mar 9, 2024
1 parent 3d93f60 commit 7603159
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/HttpParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,6 @@ struct HttpParser {
}
return unsignedIntegerValue;
}

/* RFC 9110 5.6.2. Tokens */
static inline bool isFieldNameByte(unsigned char c)
{
return (c > 32) & (c < 127) & (c != '(') &
(c != ')') & (c != ',') & (c != '/') &
(c != ':') & (c != ';') & (c != '<') &
(c != '=') & (c != '>') & (c != '?') &
(c != '@') & (c != '[') & (c != '\\') &
(c != ']') & (c != '{') & (c != '}');
}

static inline uint64_t hasLess(uint64_t x, uint64_t n) {
return (((x)-~0ULL/255*(n))&~(x)&~0ULL/255*128);
Expand All @@ -248,13 +237,25 @@ struct HttpParser {
hasMore(x, 'z');
}

/* RFC 9110 5.6.2. Tokens */
/* Hyphen is not checked here as it is very common */
static inline bool isUnlikelyFieldNameByte(unsigned char c)
{
/* Digits and 14 of the 15 non-alphanum characters (lacking hyphen) */
return (c == '~' | c == '|' | c == '`' | c == '_' | c == '^' | c == '.' | c == '+' | c == '*'
| c == '\'' | c == '&' | c == '%' | c == '$' | c == '#' | c == '!') || ((c >= 48) & (c <= 57));
}

static inline bool isFieldNameByteFastLowercased(unsigned char &in) {
/* Most common is lowercase alpha and hyphen */
if (((in >= 97) & (in <= 122)) | (in == '-')) [[likely]] {
return true;
/* Second is upper case alpha */
} else if ((in >= 65) & (in <= 90)) [[unlikely]] {
in |= 32;
return true;
} else if (isFieldNameByte(in)) [[unlikely]] {
/* These are rarely used but still valid */
} else if (isUnlikelyFieldNameByte(in)) [[unlikely]] {
return true;
}
return false;
Expand Down

0 comments on commit 7603159

Please sign in to comment.