Skip to content

Commit

Permalink
A field name is really a token
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Feb 9, 2024
1 parent 7a78a91 commit 570fe76
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/HttpParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ struct HttpParser {
return unsignedIntegerValue;
}

/* RFC 9110 16.3.1 Field Name Registry (TLDR; alnum + hyphen is allowed)
* [...] It MUST conform to the field-name syntax defined in Section 5.1,
* and it SHOULD be restricted to just letters, digits,
* and hyphen ('-') characters, with the first character being a letter. */
static inline bool isFieldNameByte(unsigned char x) {
return (x == '-') |
((x > '/') & (x < ':')) |
((x > '@') & (x < '[')) |
((x > 96) & (x < '{'));
/* 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) {
Expand All @@ -249,18 +249,18 @@ struct HttpParser {
}

static inline void *consumeFieldName(char *p) {
for (; true; p += 8) {
uint64_t word;
memcpy(&word, p, sizeof(uint64_t));
if (notFieldNameWord(word)) {
//for (; true; p += 8) {
//uint64_t word;
//memcpy(&word, p, sizeof(uint64_t));
//if (notFieldNameWord(word)) {
while (isFieldNameByte(*(unsigned char *)p)) {
*(p++) |= 0x20;
}
return (void *)p;
}
word |= 0x2020202020202020ull;
memcpy(p, &word, sizeof(uint64_t));
}
//}
//word |= 0x2020202020202020ull;
//memcpy(p, &word, sizeof(uint64_t));
//}
}

/* Puts method as key, target as value and returns non-null (or nullptr on error). */
Expand Down

0 comments on commit 570fe76

Please sign in to comment.