MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / prepare_content_receiver

Function prepare_content_receiver

dependencies/httplib/httplib.h:3390–3435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3388
3389template <typename T, typename U>
3390bool prepare_content_receiver(T &x, int &status,
3391 ContentReceiverWithProgress receiver,
3392 bool decompress, U callback) {
3393 if (decompress) {
3394 std::string encoding = x.get_header_value("Content-Encoding");
3395 std::unique_ptr<decompressor> decompressor;
3396
3397 if (encoding == "gzip" || encoding == "deflate") {
3398#ifdef CPPHTTPLIB_ZLIB_SUPPORT
3399 decompressor = detail::make_unique<gzip_decompressor>();
3400#else
3401 status = 415;
3402 return false;
3403#endif
3404 } else if (encoding.find("br") != std::string::npos) {
3405#ifdef CPPHTTPLIB_BROTLI_SUPPORT
3406 decompressor = detail::make_unique<brotli_decompressor>();
3407#else
3408 status = 415;
3409 return false;
3410#endif
3411 }
3412
3413 if (decompressor) {
3414 if (decompressor->is_valid()) {
3415 ContentReceiverWithProgress out = [&](const char *buf, size_t n,
3416 uint64_t off, uint64_t len) {
3417 return decompressor->decompress(buf, n,
3418 [&](const char *buf2, size_t n2) {
3419 return receiver(buf2, n2, off, len);
3420 });
3421 };
3422 return callback(std::move(out));
3423 } else {
3424 status = 500;
3425 return false;
3426 }
3427 }
3428 }
3429
3430 ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off,
3431 uint64_t len) {
3432 return receiver(buf, n, off, len);
3433 };
3434 return callback(std::move(out));
3435}
3436
3437template <typename T>
3438bool 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
decompressMethod · 0.80
findMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected