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

Namespaces

namespace  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:

params_t make_gzip_compress_params(int compression_level=-1)
Definition: zlib.hpp:397
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();
Zlib transformator.
Definition: zlib.hpp:475
std::string gzip_compress(string_view_t input, int compression_level=-1)
Definition: zlib.hpp:900

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();
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.
Definition: zlib.hpp:1262
Tag type for chunked output response builder.
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 Extra_Data , typename Handler >
decltype(auto) handle_body (const generic_request_t< Extra_Data > &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 1240 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 1251 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 888 of file zlib.hpp.

◆ deflate_decompress()

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

Definition at line 894 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 1262 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 900 of file zlib.hpp.

◆ gzip_decompress()

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

Definition at line 906 of file zlib.hpp.

◆ handle_body()

template<typename Extra_Data , typename Handler >
decltype(auto) restinio::transforms::zlib::handle_body ( const generic_request_t< Extra_Data > &  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();
} );
}
decltype(auto) handle_body(const generic_request_t< Extra_Data > &req, Handler &&handler)
Call a handler over a request body.
Definition: zlib.hpp:1317
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.
Since
v.0.4.4

Definition at line 1317 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 1273 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 380 of file zlib.hpp.

◆ make_deflate_decompress_params()

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

Definition at line 389 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 397 of file zlib.hpp.

◆ make_gzip_decompress_params()

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

Definition at line 406 of file zlib.hpp.

◆ make_identity_params()

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

Definition at line 414 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 878 of file zlib.hpp.

Variable Documentation

◆ default_mem_level

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

Definition at line 47 of file zlib.hpp.

◆ default_output_reserve_buffer_size

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

Default reserve buffer size for zlib transformator.

Since
v.0.4.4

Definition at line 38 of file zlib.hpp.

◆ default_strategy

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

Definition at line 48 of file zlib.hpp.

◆ default_window_bits

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

Definition at line 46 of file zlib.hpp.