Loading...
Searching...
No Matches
chunked_input_info.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <restinio/exception.hpp>
#include <restinio/http_headers.hpp>
#include <restinio/impl/include_fmtlib.hpp>
#include <vector>
#include <memory>
namespace restinio
{
//
// chunk_info_t
//
class chunk_info_t
{
std::size_t m_started_at;
std::size_t m_size;
public:
chunk_info_t(
std::size_t started_at,
std::size_t size )
: m_started_at{ started_at }
, m_size{ size }
{}
RESTINIO_NODISCARD
std::size_t
started_at() const noexcept { return m_started_at; }
RESTINIO_NODISCARD
std::size_t
size() const noexcept { return m_size; }
RESTINIO_NODISCARD
string_view_t
make_string_view_nonchecked( string_view_t full_body ) const noexcept
{
return full_body.substr( m_started_at, m_size );
}
RESTINIO_NODISCARD
string_view_t
make_string_view( string_view_t full_body ) const
{
if( m_started_at >= full_body.size() ||
m_started_at + m_size > full_body.size() )
{
throw exception_t{
fmt::format(
RESTINIO_FMT_FORMAT_STRING(
"unable to make a chunk (started_at:{}, size: {}) "
"from a body with length:{}" ),
m_started_at,
m_size,
full_body.size() )
};
}
return make_string_view_nonchecked( full_body );
}
};
namespace impl
{
//
// chunked_input_info_block_t
//
struct chunked_input_info_block_t
{
std::vector< chunk_info_t > m_chunks;
http_header_fields_t m_trailing_fields;
};
} /* namespace impl */
//
// chunked_input_info_t
//
class chunked_input_info_t
{
impl::chunked_input_info_block_t m_info;
public:
chunked_input_info_t() = default;
chunked_input_info_t(
impl::chunked_input_info_block_t info )
: m_info{ std::move(info) }
{}
RESTINIO_NODISCARD
std::size_t
chunk_count() const noexcept { return m_info.m_chunks.size(); }
RESTINIO_NODISCARD
const chunk_info_t &
chunk_at_nochecked( std::size_t index ) const noexcept
{
return m_info.m_chunks[ index ];
}
RESTINIO_NODISCARD
const chunk_info_t &
chunk_at( std::size_t index ) const
{
return m_info.m_chunks.at( index );
}
RESTINIO_NODISCARD
const auto &
chunks() const noexcept
{
return m_info.m_chunks;
}
RESTINIO_NODISCARD
const http_header_fields_t &
trailing_fields() const noexcept
{
return m_info.m_trailing_fields;
}
};
//
// chunked_input_info_unique_ptr_t
//
using chunked_input_info_unique_ptr_t =
std::unique_ptr< chunked_input_info_t >;
} /* namespace restinio */
restinio::chunk_info_t
Information about one chunk in an incoming request with chunked encoding.
Definition: chunked_input_info.hpp:41
restinio::chunk_info_t::make_string_view
RESTINIO_NODISCARD string_view_t make_string_view(string_view_t full_body) const
Extract the chunk value from the whole body.
Definition: chunked_input_info.hpp:86
restinio::chunk_info_t::chunk_info_t
chunk_info_t(std::size_t started_at, std::size_t size)
Initializing constructor.
Definition: chunked_input_info.hpp:47
restinio::chunk_info_t::m_size
std::size_t m_size
Definition: chunked_input_info.hpp:43
restinio::chunk_info_t::started_at
RESTINIO_NODISCARD std::size_t started_at() const noexcept
Get the starting offset of chunk.
Definition: chunked_input_info.hpp:57
restinio::chunk_info_t::size
RESTINIO_NODISCARD std::size_t size() const noexcept
Get the size of chunk.
Definition: chunked_input_info.hpp:62
restinio::chunk_info_t::make_string_view_nonchecked
RESTINIO_NODISCARD string_view_t make_string_view_nonchecked(string_view_t full_body) const noexcept
Extract the chunk value from the whole body.
Definition: chunked_input_info.hpp:73
restinio::chunk_info_t::m_started_at
std::size_t m_started_at
Definition: chunked_input_info.hpp:42
restinio::chunked_input_info_t
An information about chunks and trailing fields in the incoming request.
Definition: chunked_input_info.hpp:145
restinio::chunked_input_info_t::chunk_at
RESTINIO_NODISCARD const chunk_info_t & chunk_at(std::size_t index) const
Get reference to the description of a chunk by index.
Definition: chunked_input_info.hpp:190
restinio::chunked_input_info_t::chunk_count
RESTINIO_NODISCARD std::size_t chunk_count() const noexcept
Get the count of chunks.
Definition: chunked_input_info.hpp:169
restinio::chunked_input_info_t::chunk_at_nochecked
RESTINIO_NODISCARD const chunk_info_t & chunk_at_nochecked(std::size_t index) const noexcept
Get reference to the description of a chunk by index.
Definition: chunked_input_info.hpp:179
restinio::chunked_input_info_t::m_info
impl::chunked_input_info_block_t m_info
Actual data.
Definition: chunked_input_info.hpp:147
restinio::chunked_input_info_t::chunks
RESTINIO_NODISCARD const auto & chunks() const noexcept
Get access to the container with description of chunks.
Definition: chunked_input_info.hpp:204
restinio::chunked_input_info_t::chunked_input_info_t
chunked_input_info_t(impl::chunked_input_info_block_t info)
Initializing constructor.
Definition: chunked_input_info.hpp:158
restinio::chunked_input_info_t::chunked_input_info_t
chunked_input_info_t()=default
Default constructor. Makes empty object.
restinio::chunked_input_info_t::trailing_fields
RESTINIO_NODISCARD const http_header_fields_t & trailing_fields() const noexcept
Get access to the container with trailing fields.
Definition: chunked_input_info.hpp:217
restinio::exception_t
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
restinio::http_header_fields_t
Header fields map.
Definition: http_headers.hpp:703
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:36
exception.hpp
http_headers.hpp
include_fmtlib.hpp
A special wrapper around fmtlib include files.
RESTINIO_FMT_FORMAT_STRING
#define RESTINIO_FMT_FORMAT_STRING(s)
Definition: include_fmtlib.hpp:92
restinio
Definition: asio_include.hpp:21
restinio::chunked_input_info_unique_ptr_t
std::unique_ptr< chunked_input_info_t > chunked_input_info_unique_ptr_t
Alias of unique_ptr for chunked_input_info.
Definition: chunked_input_info.hpp:232
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
std
STL namespace.
restinio::impl::chunked_input_info_block_t
Bunch of data related to chunked input.
Definition: chunked_input_info.hpp:118
restinio::impl::chunked_input_info_block_t::m_chunks
std::vector< chunk_info_t > m_chunks
All non-empty chunks from the input.
Definition: chunked_input_info.hpp:120
restinio::impl::chunked_input_info_block_t::m_trailing_fields
http_header_fields_t m_trailing_fields
Trailing fields found in the input.
Definition: chunked_input_info.hpp:127
const
#define const
Definition: zconf.h:230