5 #include <boost/beast.hpp> 38 template <
class Allocator>
39 bool handle_compression(
const boost::beast::http::basic_fields<Allocator>& in_head, boost::beast::http::basic_fields<Allocator>& out_head,
43 const auto in_algs = in_head[boost::beast::http::field::accept_encoding];
46 flatmap<std::string_view, float> accepted_values;
47 for (
auto [full, name, weight] : ctre::range<weigthed_encodings_pattern>(in_algs)) {
50 const std::string w_str = {weight.to_view().data(), weight.to_view().size()};
51 w = std::atof(w_str.c_str());
55 accepted_values[name.to_view()] = w;
63 if (
const auto it = accepted_values.find(
"identity"sv); it != accepted_values.end() && it->second == 0.0f)
67 if (
const auto it = accepted_values.find(
"gzip"sv); it != accepted_values.end()) {
70 out_head.set(boost::beast::http::field::content_encoding,
"gzip");
73 if (
const auto it = accepted_values.find(
"deflate"sv); it != accepted_values.end()) {
76 out_head.set(boost::beast::http::field::content_encoding,
"deflate");
Algs
Definition: compression.hpp:14
static constexpr ctll::fixed_string weigthed_encodings_pattern
Definition: compression.hpp:26
bool handle_compression(const boost::beast::http::basic_fields< Allocator > &in_head, boost::beast::http::basic_fields< Allocator > &out_head, std::string &body)
Definition: compression.hpp:39
bool compress(std::string &body, Mode mode) noexcept
Definition: libdeflate.hpp:12