138 if( level_value < -1 || level_value > 9 )
143 "invalid compression level: {}, must be "
144 "an integer value in the range of -1 to 9" ),
157 return std::move( this->
level( level_value ) );
189 if( ( window_bits_value < 8 || window_bits_value > MAX_WBITS ) &&
195 "invalid window_bits: {}, must be "
196 "an integer value in the range of 8 to {} or "
197 "0 for decompress operation" ),
202 if( 8 == window_bits_value )
203 window_bits_value = 9;
214 return std::move( this->
window_bits( window_bits_value ) );
236 if( mem_level_value < 1 || mem_level_value > MAX_MEM_LEVEL )
241 "invalid compression mem_level: {}, must be "
242 "an integer value in the range of 1 to {}" ),
256 return std::move( this->
mem_level( mem_level_value ) );
276 if( Z_DEFAULT_STRATEGY != strategy_value &&
277 Z_FILTERED != strategy_value &&
278 Z_HUFFMAN_ONLY != strategy_value &&
279 Z_RLE != strategy_value )
284 "invalid compression strategy: {}, must be "
286 "Z_DEFAULT_STRATEGY({}), "
288 "Z_HUFFMAN_ONLY({}), "
306 return std::move( this->
strategy( strategy_value ) );
325 throw exception_t{
"too small reserve buffer size" };
496 auto current_window_bits =
m_params.window_bits();
500 current_window_bits += 16;
520 current_window_bits );
523 if( Z_OK != init_result )
528 "Failed to initialize zlib stream: {}, {}" ),
581 if( std::numeric_limits<
decltype(
m_zlib_stream.avail_in ) >::max() < input.size() )
586 "input data is too large: {} (max possible: {}), "
587 "try to break large data into pieces" ),
589 std::numeric_limits<
decltype(
m_zlib_stream.avail_in ) >::max() ) };
592 if( 0 < input.size() )
595 reinterpret_cast< Bytef*
>(
const_cast< char*
>( input.data() ) );
597 m_zlib_stream.avail_in =
static_cast< uInt
>( input.size() );
690 result.resize( data_size );
710 const char * err_msg =
"<no zlib error description>";
722 throw exception_t{
"zlib operation is already completed" };
738 reinterpret_cast< Bytef*
>(
741 const auto provided_out_buffer_size =
744 static_cast<uInt
>( provided_out_buffer_size );
746 return provided_out_buffer_size;
763 if( !( Z_OK == operation_result ||
764 Z_BUF_ERROR == operation_result ||
765 ( Z_STREAM_END == operation_result && Z_FINISH ==
flush ) ) )
767 const char * err_msg =
"<no error desc>";
774 "unexpected result of deflate() (zlib): {}, {}" ),
781 if( 0 ==
m_zlib_stream.avail_out && Z_STREAM_END != operation_result )
812 if( !( Z_OK == operation_result ||
813 Z_BUF_ERROR == operation_result ||
814 Z_STREAM_END == operation_result ) )
819 "unexpected result of inflate() (zlib): {}, {}" ),
826 if( 0 ==
m_zlib_stream.avail_out && Z_STREAM_END != operation_result )
836 if( Z_STREAM_END == operation_result )
899 return z.giveaway_output();
931template <
typename Response_Output_Strategy >
952 if(
nullptr == ztransformator )
961 std::string result{
"identity" };
965 result.assign(
"deflate" );
969 result.assign(
"gzip" );
982template <
typename Response_Output_Strategy,
typename Descendant >
996 restinio::http_field::content_encoding,
1018template <
typename X_Controlled_Output,
typename Descendant >
1025 using base_type_t::base_type_t;
1033 return static_cast< Descendant &
>( *this );
1073 restinio_controlled_output_t,
1074 body_appender_t< restinio_controlled_output_t > >
1091 using base_type_t::base_type_t;
1120 user_controlled_output_t,
1121 body_appender_t< user_controlled_output_t > >
1181 body_appender_t< chunked_output_t > >
1189 using base_type_t::base_type_t;
1217 m_ztransformator->flush();
1220 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1253template <
typename Response_Output_Strategy >
1254body_appender_t< Response_Output_Strategy >
1264template <
typename Response_Output_Strategy >
1265body_appender_t< Response_Output_Strategy >
1268 int compression_level = -1 )
1275template <
typename Response_Output_Strategy >
1276inline body_appender_t< Response_Output_Strategy >
1279 int compression_level = -1 )
1286template <
typename Response_Output_Strategy >
1287inline body_appender_t< Response_Output_Strategy >
1330template <
typename Extra_Data,
typename Handler >
1334 Handler && handler )
1338 const auto content_encoding =
1341 if( is_equal_caseless( content_encoding,
"deflate" ) )
1345 else if( is_equal_caseless( content_encoding,
"gzip" ) )
1349 else if( !is_equal_caseless( content_encoding,
"identity" ) )
1358 return handler( req.
body() );
Exception class for all exceptions thrown by RESTinio.
const http_request_header_t & header() const noexcept
Get request header.
const std::string & body() const noexcept
Get request body.
Forbid arbitrary response_builder_t instantiations.
std::unique_ptr< zlib_t > m_ztransformator
body_appender_base_t(body_appender_base_t &&ba) noexcept
body_appender_base_t(const body_appender_base_t &)=delete
body_appender_base_t(const params_t ¶ms, resp_t &resp)
response_builder_t< Response_Output_Strategy > resp_t
body_appender_base_t & operator=(const body_appender_base_t &)=delete
virtual ~body_appender_base_t()
void flush()
Flushes currently available compressed data with possibly creating new chunk and then flushes target ...
auto & append(string_view_t input)
Append data to be compressed.
auto & make_chunk(string_view_t input=string_view_t{})
Append data to be compressed and adds current zlib transformator output as a new chunk.
void complete()
Complete zlib transformation operation.
body_appender_base_t< chunked_output_t, body_appender_t< chunked_output_t > > base_type_t
auto size() const
Get the size of transformed body.
x_controlled_output_body_appender_base_t< restinio_controlled_output_t, body_appender_t< restinio_controlled_output_t > > base_type_t
x_controlled_output_body_appender_base_t< user_controlled_output_t, body_appender_t< user_controlled_output_t > > base_type_t
Base class for body appenders with restinio or user controlled output.
Descendant & append(string_view_t input)
Append a piece of data to response.
body_appender_base_t< X_Controlled_Output, Descendant > base_type_t
void complete()
Complete zlib transformation operation.
A special wrapper around fmtlib include files.
#define RESTINIO_FMT_FORMAT_STRING(s)
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
std::string_view string_view_t
Helpers for caseless comparison of strings.
Tag type for chunked output response builder.
Tag type for RESTinio controlled output response builder.
Tag type for user controlled output response builder.