| 3388 | |
| 3389 | template <typename T, typename U> |
| 3390 | bool 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 | |
| 3437 | template <typename T> |
| 3438 | bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status, |
no test coverage detected