| 3601 | |
| 3602 | template <typename T, typename U> |
| 3603 | bool 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 | |
| 3650 | template <typename T> |
| 3651 | bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status, |
no test coverage detected