Skip to content

Commit 7603159

Browse files
committed
DQUOTE is not a valid field name char
1 parent 3d93f60 commit 7603159

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/HttpParser.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,6 @@ struct HttpParser {
216216
}
217217
return unsignedIntegerValue;
218218
}
219-
220-
/* RFC 9110 5.6.2. Tokens */
221-
static inline bool isFieldNameByte(unsigned char c)
222-
{
223-
return (c > 32) & (c < 127) & (c != '(') &
224-
(c != ')') & (c != ',') & (c != '/') &
225-
(c != ':') & (c != ';') & (c != '<') &
226-
(c != '=') & (c != '>') & (c != '?') &
227-
(c != '@') & (c != '[') & (c != '\\') &
228-
(c != ']') & (c != '{') & (c != '}');
229-
}
230219

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

240+
/* RFC 9110 5.6.2. Tokens */
241+
/* Hyphen is not checked here as it is very common */
242+
static inline bool isUnlikelyFieldNameByte(unsigned char c)
243+
{
244+
/* Digits and 14 of the 15 non-alphanum characters (lacking hyphen) */
245+
return (c == '~' | c == '|' | c == '`' | c == '_' | c == '^' | c == '.' | c == '+' | c == '*'
246+
| c == '\'' | c == '&' | c == '%' | c == '$' | c == '#' | c == '!') || ((c >= 48) & (c <= 57));
247+
}
248+
251249
static inline bool isFieldNameByteFastLowercased(unsigned char &in) {
250+
/* Most common is lowercase alpha and hyphen */
252251
if (((in >= 97) & (in <= 122)) | (in == '-')) [[likely]] {
253252
return true;
253+
/* Second is upper case alpha */
254254
} else if ((in >= 65) & (in <= 90)) [[unlikely]] {
255255
in |= 32;
256256
return true;
257-
} else if (isFieldNameByte(in)) [[unlikely]] {
257+
/* These are rarely used but still valid */
258+
} else if (isUnlikelyFieldNameByte(in)) [[unlikely]] {
258259
return true;
259260
}
260261
return false;

0 commit comments

Comments
 (0)