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

Function prepare_content_receiver

examples/server/httplib.h:3603–3648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3601
3602template <typename T, typename U>
3603bool prepare_content_receiver(T &x, int &status,
3604 ContentReceiverWithProgress receiver,
3605 bool decompress, U callback) {
3606 if (decompress) {
3607 std::string encoding = x.get_header_value("Content-Encoding");
3608 std::unique_ptr<decompressor> decompressor;
3609
3610 if (encoding == "gzip" || encoding == "deflate") {
3611#ifdef CPPHTTPLIB_ZLIB_SUPPORT
3612 decompressor = detail::make_unique<gzip_decompressor>();
3613#else
3614 status = 415;
3615 return false;
3616#endif
3617 } else if (encoding.find("br") != std::string::npos) {
3618#ifdef CPPHTTPLIB_BROTLI_SUPPORT
3619 decompressor = detail::make_unique<brotli_decompressor>();
3620#else
3621 status = 415;
3622 return false;
3623#endif
3624 }
3625
3626 if (decompressor) {
3627 if (decompressor->is_valid()) {
3628 ContentReceiverWithProgress out = [&](const char *buf, size_t n,
3629 uint64_t off, uint64_t len) {
3630 return decompressor->decompress(buf, n,
3631 [&](const char *buf2, size_t n2) {
3632 return receiver(buf2, n2, off, len);
3633 });
3634 };
3635 return callback(std::move(out));
3636 } else {
3637 status = 500;
3638 return false;
3639 }
3640 }
3641 }
3642
3643 ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off,
3644 uint64_t len) {
3645 return receiver(buf, n, off, len);
3646 };
3647 return callback(std::move(out));
3648}
3649
3650template <typename T>
3651bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status,

Callers 1

read_contentFunction · 0.85

Calls 4

get_header_valueMethod · 0.80
findMethod · 0.80
decompressMethod · 0.80
is_validMethod · 0.45

Tested by

no test coverage detected