MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / read_content_chunked

Function read_content_chunked

examples/server/httplib.h:3543–3595  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3541
3542template <typename T>
3543inline bool read_content_chunked(Stream &strm, T &x,
3544 ContentReceiverWithProgress out) {
3545 const auto bufsiz = 16;
3546 char buf[bufsiz];
3547
3548 stream_line_reader line_reader(strm, buf, bufsiz);
3549
3550 if (!line_reader.getline()) { return false; }
3551
3552 unsigned long chunk_len;
3553 while (true) {
3554 char *end_ptr;
3555
3556 chunk_len = std::strtoul(line_reader.ptr(), &end_ptr, 16);
3557
3558 if (end_ptr == line_reader.ptr()) { return false; }
3559 if (chunk_len == ULONG_MAX) { return false; }
3560
3561 if (chunk_len == 0) { break; }
3562
3563 if (!read_content_with_length(strm, chunk_len, nullptr, out)) {
3564 return false;
3565 }
3566
3567 if (!line_reader.getline()) { return false; }
3568
3569 if (strcmp(line_reader.ptr(), "\r\n")) { return false; }
3570
3571 if (!line_reader.getline()) { return false; }
3572 }
3573
3574 assert(chunk_len == 0);
3575
3576 // Trailer
3577 if (!line_reader.getline()) { return false; }
3578
3579 while (strcmp(line_reader.ptr(), "\r\n")) {
3580 if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }
3581
3582 // Exclude line terminator
3583 constexpr auto line_terminator_len = 2;
3584 auto end = line_reader.ptr() + line_reader.size() - line_terminator_len;
3585
3586 parse_header(line_reader.ptr(), end,
3587 [&](std::string &&key, std::string &&val) {
3588 x.headers.emplace(std::move(key), std::move(val));
3589 });
3590
3591 if (!line_reader.getline()) { return false; }
3592 }
3593
3594 return true;
3595}
3596
3597inline bool is_chunked_transfer_encoding(const Headers &headers) {
3598 return !strcasecmp(get_header_value(headers, "Transfer-Encoding", 0, ""),

Callers 1

read_contentFunction · 0.85

Calls 5

read_content_with_lengthFunction · 0.85
getlineMethod · 0.80
parse_headerFunction · 0.70
ptrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected