Go to the documentation of this file.
138 if( level_value < -1 || level_value > 9 )
142 "invalid compression level: {}, must be "
143 "an integer value in the range of -1 to 9",
188 if( ( window_bits_value < 8 || window_bits_value >
MAX_WBITS ) &&
193 "invalid window_bits: {}, must be "
194 "an integer value in the range of 8 to {} or "
195 "0 for decompress operation",
200 if( 8 == window_bits_value )
201 window_bits_value = 9;
238 "invalid compression mem_level: {}, must be "
239 "an integer value in the range of 1 to {}",
276 Z_RLE != strategy_value )
280 "invalid compression strategy: {}, must be "
282 "Z_DEFAULT_STRATEGY({}), ",
284 "Z_HUFFMAN_ONLY({}), ",
321 throw exception_t{
"too small reserve buffer size" };
496 current_window_bits += 16;
516 current_window_bits );
519 if(
Z_OK != init_result )
523 "Failed to initialize zlib stream: {}, {}",
580 "input data is too large: {} (max possible: {}), "
581 "try to break large data into pieces",
586 if( 0 < input.size() )
589 reinterpret_cast< Bytef*
>(
const_cast< char*
>( input.data() ) );
684 result.resize( data_size );
704 const char * err_msg =
"<no zlib error description>";
716 throw exception_t{
"zlib operation is already completed" };
732 reinterpret_cast< Bytef*
>(
735 const auto provided_out_buffer_size =
738 static_cast<uInt>( provided_out_buffer_size );
740 return provided_out_buffer_size;
757 if( !(
Z_OK == operation_result ||
761 const char * err_msg =
"<no error desc>";
767 "unexpected result of deflate() (zlib): {}, {}",
805 if( !(
Z_OK == operation_result ||
811 "unexpected result of inflate() (zlib): {}, {}",
884 return z.giveaway_output();
916 template <
typename Response_Output_Strategy >
937 if(
nullptr == ztransformator )
946 std::string result{
"identity" };
950 result.assign(
"deflate" );
954 result.assign(
"gzip" );
967 template <
typename Response_Output_Strategy,
typename Descendant >
981 restinio::http_field::content_encoding,
1003 template <
typename X_Controlled_Output,
typename Descendant >
1010 using base_type_t::base_type_t;
1018 return static_cast< Descendant &
>( *this );
1058 restinio_controlled_output_t,
1059 body_appender_t< restinio_controlled_output_t > >
1073 return m_ztransformator->output_size();
1076 using base_type_t::base_type_t;
1105 user_controlled_output_t,
1106 body_appender_t< user_controlled_output_t > >
1120 m_ztransformator->flush();
1122 .append_body( m_ztransformator->giveaway_output() )
1166 body_appender_t< chunked_output_t > >
1174 using base_type_t::base_type_t;
1186 m_ztransformator->write( input );
1202 m_ztransformator->flush();
1205 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1217 if( !m_ztransformator->is_completed() )
1219 m_ztransformator->flush();
1220 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1231 m_ztransformator->complete();
1232 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1238 template <
typename Response_Output_Strategy >
1239 body_appender_t< Response_Output_Strategy >
1249 template <
typename Response_Output_Strategy >
1250 body_appender_t< Response_Output_Strategy >
1253 int compression_level = -1 )
1260 template <
typename Response_Output_Strategy >
1261 inline body_appender_t< Response_Output_Strategy >
1264 int compression_level = -1 )
1271 template <
typename Response_Output_Strategy >
1272 inline body_appender_t< Response_Output_Strategy >
1315 template <
typename Handler >
1321 const auto content_encoding =
1322 req.header().get_field_or( restinio::http_field::content_encoding,
"identity" );
1335 fmt::format(
"content-encoding '{}' not supported", content_encoding ) };
1338 return handler( req.body() );
Descendant & append(string_view_t input)
Append a piece of data to response.
Exception class for all exceptions thrown by RESTinio.
Tag type for user controlled output response builder.
Tag type for RESTinio controlled output response builder.
std::unique_ptr< zlib_t > m_ztransformator
int ZEXPORT deflateEnd(z_streamp strm)
body_appender_base_t & operator=(const body_appender_base_t &)=delete
nonstd::string_view string_view_t
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.
Tag type for chunked output response builder.
void flush()
Flushes currently available compressed data with possibly creating new chunk and then flushes target ...
Base class for body appenders.
void complete()
Complete zlib transformation operation.
#define inflateInit2(strm, windowBits)
A special wrapper around fmtlib include files.
body_appender_base_t(const params_t ¶ms, resp_t &resp)
virtual ~body_appender_base_t()
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
Base class for body appenders with restinio or user controlled output.
auto size() const
Get the size of transformed body.
#define Z_DEFAULT_STRATEGY
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
auto & append(string_view_t input)
Append data to be compressed.
body_appender_base_t(const body_appender_base_t &)=delete
Helpers for caseless comparison of strings.
int ZEXPORT deflate(z_streamp strm, int flush)
Forbid arbitrary response_builder_t instantiations.
void swap(optional< T > &x, optional< T > &y)
body_appender_base_t(body_appender_base_t &&ba) noexcept
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT inflate(z_streamp strm, int flush)