2
3
6
7
8
9
13#include <restinio/impl/include_fmtlib.hpp>
15#include <restinio/impl/string_caseless_compare.hpp>
17#include <restinio/exception.hpp>
18#include <restinio/string_view.hpp>
19#include <restinio/message_builders.hpp>
20#include <restinio/request_handler.hpp>
41
42
43
44
57
58
59
60
61
62
91
92
93
94
95
125
126
131
132
133
134
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
) );
165
166
167
168
169
170
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;
219
220
225
226
227
228
229
230
231
232
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 {}" ),
261
262
267
268
269
270
271
272
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({}), "
311
312
313
314
315
316
352
353
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
500 current_window_bits += 16;
520 current_window_bits );
523 if( Z_OK != init_result )
528 "Failed to initialize zlib stream: {}, {}" ),
566
567
568
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() );
613
614
615
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
690 result.resize( data_size );
710 const char * err_msg =
"<no zlib error description>";
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;
751
752
753
759 const auto provided_out_buffer_size = prepare_out_buffer();
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 )
801
802
803
809 const auto provided_out_buffer_size = prepare_out_buffer();
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 )
856
857
858
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
905 return transform( input, make_deflate_compress_params( compression_level ) );
911 return transform( input, make_deflate_decompress_params() );
917 return transform( input, make_gzip_compress_params( compression_level ) );
923 return transform( input, make_gzip_decompress_params() );
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 >
992 impl::ensure_is_compression_operation(
993 m_ztransformator->params().operation() );
995 m_resp.append_header(
996 restinio::http_field::content_encoding,
997 impl::content_encoding_token(
998 m_ztransformator->params().format() ) );
1018template <
typename X_Controlled_Output,
typename Descendant >
1032 this->m_ztransformator->write( input );
1033 return static_cast< Descendant & >( *
this );
1042 this->m_ztransformator->complete();
1044 this->m_resp.append_body(
this->m_ztransformator->giveaway_output() );
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1086 impl::ensure_valid_transforator( m_ztransformator.get() );
1088 return m_ztransformator->output_size();
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1119 :
public x_controlled_output_body_appender_base_t<
1120 user_controlled_output_t,
1121 body_appender_t< user_controlled_output_t > >
1134 impl::ensure_valid_transforator( m_ztransformator.get() );
1135 m_ztransformator->flush();
1137 .append_body( m_ztransformator->giveaway_output() )
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1179 :
public body_appender_base_t<
1181 body_appender_t< chunked_output_t > >
1193
1194
1195
1199 impl::ensure_valid_transforator( m_ztransformator.get() );
1201 m_ztransformator->write( input );
1208
1209
1210
1211
1217 m_ztransformator->flush();
1220 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1230 impl::ensure_valid_transforator( m_ztransformator.get() );
1232 if( !m_ztransformator->is_completed() )
1234 m_ztransformator->flush();
1235 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1245 impl::ensure_valid_transforator( m_ztransformator.get() );
1246 m_ztransformator->complete();
1247 m_resp.append_chunk( m_ztransformator->giveaway_output() );
1253template <
typename Response_Output_Strategy >
1264template <
typename Response_Output_Strategy >
1268 int compression_level = -1 )
1275template <
typename Response_Output_Strategy >
1279 int compression_level = -1 )
1286template <
typename Response_Output_Strategy >
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330template <
typename Extra_Data,
typename Handler >
1334 Handler && handler )
1338 const auto content_encoding =
1341 if( is_equal_caseless( content_encoding,
"deflate" ) )
1343 return handler( deflate_decompress( req.body() ) );
1345 else if( is_equal_caseless( content_encoding,
"gzip" ) )
1347 return handler( gzip_decompress( req.body() ) );
1349 else if( !is_equal_caseless( content_encoding,
"identity" ) )
1358 return handler( req.body() );
Exception class for all exceptions thrown by RESTinio.
exception_t(const char *err)
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 & operator=(body_appender_base_t &&)=delete
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.
#define RESTINIO_FMT_FORMAT_STRING(s)
http_field_t http_field
Helper alies to omitt _t suffix.
Tag type for chunked output response builder.
Tag type for RESTinio controlled output response builder.
Tag type for user controlled output response builder.