RESTinio
Namespaces | Classes | Variables
restinio::transforms::zlib Namespace Reference

Namespaces

 impl
 

Classes

class  body_appender_base_t
 Base class for body appenders. More...
 
class  body_appender_t
 
class  body_appender_t< chunked_output_t >
 
class  body_appender_t< restinio_controlled_output_t >
 
class  body_appender_t< user_controlled_output_t >
 
class  params_t
 Parameters of performing data transformation with zlib. More...
 
class  x_controlled_output_body_appender_base_t
 Base class for body appenders with restinio or user controlled output. More...
 
class  zlib_t
 Zlib transformator. More...
 

Functions

Create parameters for zlib transformators.

A set of function helping to create params_t objects ommiting some verbose deteils.

Instead of writing something like this:

It is better to write the following:

Since
v.0.4.4
params_t make_deflate_compress_params (int compression_level=-1)
 
params_t make_deflate_decompress_params ()
 
params_t make_gzip_compress_params (int compression_level=-1)
 
params_t make_gzip_decompress_params ()
 
params_t make_identity_params ()
 
Helper functions for doing zlib transformation with less boilerplate.

A set of handy functions helping to perform zlib transform in one line.

Instead of writing something like this:

z.write( data );
z.complete();
body = z.giveaway_output();

It is possible to write the following:

Since
v.0.4.4
std::string transform (string_view_t input, const params_t &params)
 Do a specified zlib transformation. More...
 
std::string deflate_compress (string_view_t input, int compression_level=-1)
 
std::string deflate_decompress (string_view_t input)
 
std::string gzip_compress (string_view_t input, int compression_level=-1)
 
std::string gzip_decompress (string_view_t input)
 
Body appender.

Helper class for setting the body of response_builder_t<chunked_output_t>.

Sample usage:

auto resp = req->create_response<chunked_output_t>();
resp.append_header( restinio::http_field::server, "RESTinio" )
.append_header_date_field()
.append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" );
auto ba = rtz::gzip_body_appender( resp );
ba.append( some_data );
ba.append( some_more_data );
ba.make_chunk(); // Flush copressed data and creates a chunk with it.
ba.flush(); // Send currently prepared chunks to client
// ...
// Copress the data and creates a chunk with it.
ba.make_chunk( even_more_data );
ba.flush(); // Send currently prepared chunks to client
// ...
ba.append( yet_even_more_data );
ba.append( last_data );
ba.complete(); // Creates last chunk, but doesn't send it to client.
ba.flush(); // Send chunk created by complete() call
// ...
resp.done();
Since
v.0.4.4
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > body_appender (response_builder_t< Response_Output_Strategy > &resp, const params_t &params)
 Create body appender with given zlib transformation parameters. More...
 
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > deflate_body_appender (response_builder_t< Response_Output_Strategy > &resp, int compression_level=-1)
 Create body appender with deflate transformation and a given compression level. More...
 
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > gzip_body_appender (response_builder_t< Response_Output_Strategy > &resp, int compression_level=-1)
 Create body appender with gzip transformation and a given compression level. More...
 
template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > identity_body_appender (response_builder_t< Response_Output_Strategy > &resp, int=-1)
 Create body appender with gzip transformation and a given compression level. More...
 
template<typename Handler >
decltype(auto) handle_body (const request_t &req, Handler handler)
 Call a handler over a request body. More...
 

Variables

constexpr std::size_t default_output_reserve_buffer_size = 256 * 1024
 Default reserve buffer size for zlib transformator. More...
 
Default values for zlib tuning parameters.

Constants are defined with values provided by zlib.

Since
v.0.4.4
constexpr int default_window_bits = MAX_WBITS
 
constexpr int default_mem_level = MAX_MEM_LEVEL
 
constexpr int default_strategy = Z_DEFAULT_STRATEGY
 

Function Documentation

◆ body_appender()

template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > restinio::transforms::zlib::body_appender ( response_builder_t< Response_Output_Strategy > &  resp,
const params_t params 
)

Create body appender with given zlib transformation parameters.

Since
v.0.4.4

Definition at line 1238 of file zlib.hpp.

◆ deflate_body_appender()

template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > restinio::transforms::zlib::deflate_body_appender ( response_builder_t< Response_Output_Strategy > &  resp,
int  compression_level = -1 
)

Create body appender with deflate transformation and a given compression level.

Since
v.0.4.4

Definition at line 1249 of file zlib.hpp.

◆ deflate_compress()

std::string restinio::transforms::zlib::deflate_compress ( string_view_t  input,
int  compression_level = -1 
)
inline

Definition at line 886 of file zlib.hpp.

◆ deflate_decompress()

std::string restinio::transforms::zlib::deflate_decompress ( string_view_t  input)
inline

Definition at line 892 of file zlib.hpp.

◆ gzip_body_appender()

template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > restinio::transforms::zlib::gzip_body_appender ( response_builder_t< Response_Output_Strategy > &  resp,
int  compression_level = -1 
)
inline

Create body appender with gzip transformation and a given compression level.

Since
v.0.4.4

Definition at line 1260 of file zlib.hpp.

◆ gzip_compress()

std::string restinio::transforms::zlib::gzip_compress ( string_view_t  input,
int  compression_level = -1 
)
inline

Definition at line 898 of file zlib.hpp.

◆ gzip_decompress()

std::string restinio::transforms::zlib::gzip_decompress ( string_view_t  input)
inline

Definition at line 904 of file zlib.hpp.

◆ handle_body()

template<typename Handler >
decltype(auto) restinio::transforms::zlib::handle_body ( const request_t req,
Handler  handler 
)

Call a handler over a request body.

If body is encoded with either 'deflate' or 'gzip' then it is decompressed and the handler is called.

If body is encoded with 'identity' (or not specified) the handler is called with original body.

In other cases an exception is thrown.

Template Parameters
Handlera function object capable to handle std::string as an argument.

Sample usage:

auto decompressed_echo_handler( restinio::request_handle_t req )
{
return
*req,
[&]( auto body ){
return
req->create_response()
.append_header( restinio::http_field::server, "RESTinio" )
.append_header_date_field()
.append_header(
restinio::http_field::content_type,
"text/plain; charset=utf-8" );
.set_body( std::move( body ) )
.done();
} );
}
Since
v.0.4.4

Definition at line 1315 of file zlib.hpp.

◆ identity_body_appender()

template<typename Response_Output_Strategy >
body_appender_t< Response_Output_Strategy > restinio::transforms::zlib::identity_body_appender ( response_builder_t< Response_Output_Strategy > &  resp,
int  = -1 
)
inline

Create body appender with gzip transformation and a given compression level.

Since
v.0.4.4

Definition at line 1271 of file zlib.hpp.

◆ make_deflate_compress_params()

params_t restinio::transforms::zlib::make_deflate_compress_params ( int  compression_level = -1)
inline

Definition at line 378 of file zlib.hpp.

◆ make_deflate_decompress_params()

params_t restinio::transforms::zlib::make_deflate_decompress_params ( )
inline

Definition at line 387 of file zlib.hpp.

◆ make_gzip_compress_params()

params_t restinio::transforms::zlib::make_gzip_compress_params ( int  compression_level = -1)
inline

Definition at line 395 of file zlib.hpp.

◆ make_gzip_decompress_params()

params_t restinio::transforms::zlib::make_gzip_decompress_params ( )
inline

Definition at line 404 of file zlib.hpp.

◆ make_identity_params()

params_t restinio::transforms::zlib::make_identity_params ( )
inline

Definition at line 412 of file zlib.hpp.

◆ transform()

std::string restinio::transforms::zlib::transform ( string_view_t  input,
const params_t params 
)
inline

Do a specified zlib transformation.

Definition at line 876 of file zlib.hpp.

Variable Documentation

◆ default_mem_level

constexpr int restinio::transforms::zlib::default_mem_level = MAX_MEM_LEVEL

Definition at line 45 of file zlib.hpp.

◆ default_output_reserve_buffer_size

constexpr std::size_t restinio::transforms::zlib::default_output_reserve_buffer_size = 256 * 1024

Default reserve buffer size for zlib transformator.

Since
v.0.4.4

Definition at line 36 of file zlib.hpp.

◆ default_strategy

constexpr int restinio::transforms::zlib::default_strategy = Z_DEFAULT_STRATEGY

Definition at line 46 of file zlib.hpp.

◆ default_window_bits

constexpr int restinio::transforms::zlib::default_window_bits = MAX_WBITS

Definition at line 44 of file zlib.hpp.