RESTinio
Loading...
Searching...
No Matches
restinio::chunk_info_t Class Reference

Information about one chunk in an incoming request with chunked encoding. More...

#include <chunked_input_info.hpp>

Public Member Functions

 chunk_info_t (std::size_t started_at, std::size_t size, chunk_ext_params_unique_ptr_t ext_params)
 Initializing constructor.
std::size_t started_at () const noexcept
 Get the starting offset of chunk.
std::size_t size () const noexcept
 Get the size of chunk.
string_view_t make_string_view_nonchecked (string_view_t full_body) const noexcept
 Extract the chunk value from the whole body.
string_view_t make_string_view (string_view_t full_body) const
 Extract the chunk value from the whole body.
nullable_pointer_t< const chunk_ext_params_text_params () const noexcept
 Get a list of chunk extension's params.

Private Attributes

std::size_t m_started_at
std::size_t m_size
chunk_ext_params_unique_ptr_t m_ext_params
 Storage of chunk extension parameters.

Detailed Description

Information about one chunk in an incoming request with chunked encoding.

In RESTinio v.0.6.9 all chunks are concatenated into the one body. The information about individual chunks preserved in the form of vector of chunk_info_t objects. Every object contains the offset from the begining of the concatenated body and the size of the chunk. This information allows to extract the corresponding fragment from the whole body.

Since
v.0.6.9

Definition at line 58 of file chunked_input_info.hpp.

Constructor & Destructor Documentation

◆ chunk_info_t()

restinio::chunk_info_t::chunk_info_t ( std::size_t started_at,
std::size_t size,
chunk_ext_params_unique_ptr_t ext_params )
inline

Initializing constructor.

Definition at line 73 of file chunked_input_info.hpp.

Member Function Documentation

◆ ext_params()

nullable_pointer_t< const chunk_ext_params_t > restinio::chunk_info_t::ext_params ( ) const
inlinenodiscardnoexcept

Get a list of chunk extension's params.

In case this chunk has extensions this function returns a valid pointer to a vector of ext parameters (name-value pairs).

auto handle_request( restinio::request_t req ) {
const auto * chunked_input = req.chunked_input_info();
if( !chunked_input )
{
}
auto resp = req->create_response()
.append_header_date_field()
.append_header( "Content-Type", "text/plain; charset=utf-8" );
int i = 0;
for( const auto & ch : chunked_input->chunks() )
{
if( const auto * params = ch.ext_params(); params )
{
resp.append_body(
fmt::format(
FMT_STRING( "Chunk #{} has {} ext param(s)\r\n" ),
i++,
params->size() ) );
}
else
{
resp.append_body(
fmt::format(
FMT_STRING( "Chunk #{} has no ext params\r\n" ),
i++ ) );
}
}
return resp.done();
}
auto create_response(http_status_line_t status_line=status_ok())
nullable_pointer_t< const chunked_input_info_t > chunked_input_info() const noexcept
Get optional info about chunked input.
constexpr request_handling_status_t request_rejected() noexcept
generic_request_t< no_extra_data_factory_t::data_t > request_t
An alias for incoming request without additional extra-data.
Since
v.0.7.0

Definition at line 176 of file chunked_input_info.hpp.

◆ make_string_view()

string_view_t restinio::chunk_info_t::make_string_view ( string_view_t full_body) const
inlinenodiscard

Extract the chunk value from the whole body.

A check of possibility of extraction is performed.

Exceptions
exception_tif full_body is too small to hold the chunk.

Definition at line 114 of file chunked_input_info.hpp.

◆ make_string_view_nonchecked()

string_view_t restinio::chunk_info_t::make_string_view_nonchecked ( string_view_t full_body) const
inlinenodiscardnoexcept

Extract the chunk value from the whole body.

Attention
This method doesn't check the possibility of the extraction. An attempt of extraction of chunk from a body that is too small is undefined behavior.

Definition at line 101 of file chunked_input_info.hpp.

◆ size()

std::size_t restinio::chunk_info_t::size ( ) const
inlinenodiscardnoexcept

Get the size of chunk.

Definition at line 90 of file chunked_input_info.hpp.

◆ started_at()

std::size_t restinio::chunk_info_t::started_at ( ) const
inlinenodiscardnoexcept

Get the starting offset of chunk.

Definition at line 85 of file chunked_input_info.hpp.

Member Data Documentation

◆ m_ext_params

chunk_ext_params_unique_ptr_t restinio::chunk_info_t::m_ext_params
private

Storage of chunk extension parameters.

The instance will be allocated only if chunk has extension's parameters.

Since
v.0.7.0

Definition at line 70 of file chunked_input_info.hpp.

◆ m_size

std::size_t restinio::chunk_info_t::m_size
private

Definition at line 61 of file chunked_input_info.hpp.

◆ m_started_at

std::size_t restinio::chunk_info_t::m_started_at
private

Definition at line 60 of file chunked_input_info.hpp.


The documentation for this class was generated from the following file: