RESTinio
Loading...
Searching...
No Matches
chunked_input_info.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
11#pragma once
12
15
17
18#include <vector>
19#include <memory>
20
21namespace restinio
22{
23
24//
25// chunk_ext_param_t
26//
27
34{
35 std::string m_name;
36 std::string m_value;
37};
38
39using chunk_ext_params_t = std::vector< chunk_ext_param_t >;
40using chunk_ext_params_unique_ptr_t = std::unique_ptr< chunk_ext_params_t >;
41
42//
43// chunk_info_t
44//
59{
60 std::size_t m_started_at;
61 std::size_t m_size;
62
71public:
74 std::size_t started_at,
75 std::size_t size,
78 , m_size{ size }
79 , m_ext_params{ std::move( ext_params ) }
80 {}
81
83 [[nodiscard]]
84 std::size_t
86
88 [[nodiscard]]
89 std::size_t
90 size() const noexcept { return m_size; }
91
93
99 [[nodiscard]]
102 {
103 return full_body.substr( m_started_at, m_size );
104 }
105
107
112 [[nodiscard]]
115 {
116 if( m_started_at >= full_body.size() ||
117 m_started_at + m_size > full_body.size() )
118 {
119 throw exception_t{
120 fmt::format(
122 "unable to make a chunk (started_at:{}, size: {}) "
123 "from a body with length:{}" ),
125 m_size,
126 full_body.size() )
127 };
128 }
129
131 }
132
177 {
178 return m_ext_params.get();
179 }
180};
181
182namespace impl
183{
184
185//
186// chunked_input_info_block_t
187//
194{
196 std::vector< chunk_info_t > m_chunks;
197
199
204};
205
206} /* namespace impl */
207
208//
209// chunked_input_info_t
210//
221{
224
225public:
229
236 : m_info{ std::move(info) }
237 {}
238
240
243 [[nodiscard]]
244 std::size_t
246
248
253 [[nodiscard]]
254 const chunk_info_t &
255 chunk_at_nochecked( std::size_t index ) const noexcept
256 {
257 return m_info.m_chunks[ index ];
258 }
259
261
264 [[nodiscard]]
265 const chunk_info_t &
266 chunk_at( std::size_t index ) const
267 {
268 return m_info.m_chunks.at( index );
269 }
270
272
278 [[nodiscard]]
279 const auto &
281 {
282 return m_info.m_chunks;
283 }
284
286
291 [[nodiscard]]
297};
298
299//
300// chunked_input_info_unique_ptr_t
301//
308 std::unique_ptr< chunked_input_info_t >;
309
310} /* namespace restinio */
311
Information about one chunk in an incoming request with chunked encoding.
chunk_info_t(std::size_t started_at, std::size_t size, chunk_ext_params_unique_ptr_t ext_params)
Initializing constructor.
nullable_pointer_t< const chunk_ext_params_t > ext_params() const noexcept
Get a list of chunk extension's params.
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.
chunk_ext_params_unique_ptr_t m_ext_params
Storage of chunk extension parameters.
string_view_t make_string_view(string_view_t full_body) const
Extract the chunk value from the whole body.
An information about chunks and trailing fields in the incoming request.
const chunk_info_t & chunk_at_nochecked(std::size_t index) const noexcept
Get reference to the description of a chunk by index.
const auto & chunks() const noexcept
Get access to the container with description of chunks.
impl::chunked_input_info_block_t m_info
Actual data.
std::size_t chunk_count() const noexcept
Get the count of chunks.
const http_header_fields_t & trailing_fields() const noexcept
Get access to the container with trailing fields.
chunked_input_info_t(impl::chunked_input_info_block_t info)
Initializing constructor.
chunked_input_info_t()=default
Default constructor. Makes empty object.
const chunk_info_t & chunk_at(std::size_t index) const
Get reference to the description of a chunk by index.
Exception class for all exceptions thrown by RESTinio.
Definition exception.hpp:26
A special wrapper around fmtlib include files.
#define RESTINIO_FMT_FORMAT_STRING(s)
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
std::string_view string_view_t
std::unique_ptr< chunk_ext_params_t > chunk_ext_params_unique_ptr_t
T * nullable_pointer_t
Type for pointer that can be nullptr.
std::unique_ptr< chunked_input_info_t > chunked_input_info_unique_ptr_t
Alias of unique_ptr for chunked_input_info.
std::vector< chunk_ext_param_t > chunk_ext_params_t
Chunk extension parameter.
Bunch of data related to chunked input.
std::vector< chunk_info_t > m_chunks
All non-empty chunks from the input.
http_header_fields_t m_trailing_fields
Trailing fields found in the input.