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();
916template <
typename Response_Output_Strategy >
937 if(
nullptr == ztransformator )
946 std::string result{
"identity" };
950 result.assign(
"deflate" );
954 result.assign(
"gzip" );
967template <
typename Response_Output_Strategy,
typename Descendant >
981 restinio::http_field::content_encoding,
1003template <
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() );
1238template <
typename Response_Output_Strategy >
1239body_appender_t< Response_Output_Strategy >
1249template <
typename Response_Output_Strategy >
1250body_appender_t< Response_Output_Strategy >
1253 int compression_level = -1 )
1260template <
typename Response_Output_Strategy >
1261inline body_appender_t< Response_Output_Strategy >
1264 int compression_level = -1 )
1271template <
typename Response_Output_Strategy >
1272inline body_appender_t< Response_Output_Strategy >
1315template <
typename Extra_Data,
typename Handler >
1319 Handler && handler )
1323 const auto content_encoding =
1337 fmt::format(
"content-encoding '{}' not supported", content_encoding ) };
1340 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 compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT deflate(z_streamp strm, int flush)
A special wrapper around fmtlib include files.
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateEnd(z_streamp strm)
void swap(optional< T > &x, optional< T > &y)
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)