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 ) );
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 ) );
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" };
500 current_window_bits += 16;
520 current_window_bits );
523 if(
Z_OK != init_result )
528 "Failed to initialize zlib stream: {}, {}" ),
586 "input data is too large: {} (max possible: {}), "
587 "try to break large data into pieces" ),
592 if( 0 < input.size() )
595 reinterpret_cast< Bytef*
>(
const_cast< char*
>( input.data() ) );
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 ||
767 const char * err_msg =
"<no error desc>";
774 "unexpected result of deflate() (zlib): {}, {}" ),
812 if( !(
Z_OK == operation_result ||
819 "unexpected result of inflate() (zlib): {}, {}" ),
892 return z.giveaway_output();
924template <
typename Response_Output_Strategy >
945 if(
nullptr == ztransformator )
954 std::string result{
"identity" };
958 result.assign(
"deflate" );
962 result.assign(
"gzip" );
975template <
typename Response_Output_Strategy,
typename Descendant >
989 restinio::http_field::content_encoding,
1011template <
typename X_Controlled_Output,
typename Descendant >
1018 using base_type_t::base_type_t;
1026 return static_cast< Descendant &
>( *this );
1066 restinio_controlled_output_t,
1067 body_appender_t< restinio_controlled_output_t > >
1081 return m_ztransformator->output_size();
1084 using base_type_t::base_type_t;
1113 user_controlled_output_t,
1114 body_appender_t< user_controlled_output_t > >
1128 m_ztransformator->flush();
1130 .append_body( m_ztransformator->giveaway_output() )
1174 body_appender_t< chunked_output_t > >
1182 using base_type_t::base_type_t;
1194 m_ztransformator->write( input );
1210 m_ztransformator->flush();
1213 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1225 if( !m_ztransformator->is_completed() )
1227 m_ztransformator->flush();
1228 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1239 m_ztransformator->complete();
1240 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1246template <
typename Response_Output_Strategy >
1247body_appender_t< Response_Output_Strategy >
1257template <
typename Response_Output_Strategy >
1258body_appender_t< Response_Output_Strategy >
1261 int compression_level = -1 )
1268template <
typename Response_Output_Strategy >
1269inline body_appender_t< Response_Output_Strategy >
1272 int compression_level = -1 )
1279template <
typename Response_Output_Strategy >
1280inline body_appender_t< Response_Output_Strategy >
1323template <
typename Extra_Data,
typename Handler >
1327 Handler && handler )
1331 const auto content_encoding =
1334 if( is_equal_caseless( content_encoding,
"deflate" ) )
1338 else if( is_equal_caseless( content_encoding,
"gzip" ) )
1342 else if( !is_equal_caseless( content_encoding,
"identity" ) )
1351 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.
Base class for body appenders.
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)
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.
auto size() const
Get the size of transformed body.
Base class for body appenders with restinio or user controlled output.
Descendant & append(string_view_t input)
Append a piece of data to response.
void complete()
Complete zlib transformation operation.
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT deflate(z_streamp strm, int flush)
A special wrapper around fmtlib include files.
#define RESTINIO_FMT_FORMAT_STRING(s)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateEnd(z_streamp strm)
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
nonstd::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.
#define Z_DEFAULT_STRATEGY
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
#define inflateInit2(strm, windowBits)