Skip to content

Commit b3a4045

Browse files
committed
1 parent 5fcd8f7 commit b3a4045

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

httplib.h

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,27 @@ inline uint64_t get_header_value_uint64(const Headers &headers, const char *key,
22832283
return def;
22842284
}
22852285

2286+
inline void parse_header(const char *beg, const char *end, Headers &headers) {
2287+
auto p = beg;
2288+
while (p < end && *p != ':') {
2289+
p++;
2290+
}
2291+
if (p < end) {
2292+
auto key_end = p;
2293+
p++; // skip ':'
2294+
while (p < end && (*p == ' ' || *p == '\t')) {
2295+
p++;
2296+
}
2297+
if (p < end) {
2298+
auto val_begin = p;
2299+
while (p < end) {
2300+
p++;
2301+
}
2302+
headers.emplace(std::string(beg, key_end), std::string(val_begin, end));
2303+
}
2304+
}
2305+
}
2306+
22862307
inline bool read_headers(Stream &strm, Headers &headers) {
22872308
const auto bufsiz = 2048;
22882309
char buf[bufsiz];
@@ -2305,18 +2326,7 @@ inline bool read_headers(Stream &strm, Headers &headers) {
23052326
end--;
23062327
}
23072328

2308-
// Horizontal tab and ' ' are considered whitespace and are ignored when on
2309-
// the left or right side of the header value:
2310-
// - https://stackoverflow.com/questions/50179659/
2311-
// - https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
2312-
static const std::regex re(R"(([^:]+):[\t ]*([^\t ].*))");
2313-
2314-
std::cmatch m;
2315-
if (std::regex_match(line_reader.ptr(), end, m, re)) {
2316-
auto key = std::string(m[1]);
2317-
auto val = std::string(m[2]);
2318-
headers.emplace(key, val);
2319-
}
2329+
parse_header(line_reader.ptr(), end, headers);
23202330
}
23212331

23222332
return true;

0 commit comments

Comments
 (0)