RESTinio
chunked_input_info.hpp
Go to the documentation of this file.
1 /*
2  restinio
3 */
4 
11 #pragma once
12 
13 #include <restinio/exception.hpp>
15 
17 
18 #include <vector>
19 #include <memory>
20 
21 namespace restinio
22 {
23 
24 //
25 // chunk_info_t
26 //
41 {
42  std::size_t m_started_at;
43  std::size_t m_size;
44 
45 public:
48  std::size_t started_at,
49  std::size_t size )
51  , m_size{ size }
52  {}
53 
56  std::size_t
57  started_at() const noexcept { return m_started_at; }
58 
61  std::size_t
62  size() const noexcept { return m_size; }
63 
65 
73  make_string_view_nonchecked( string_view_t full_body ) const noexcept
74  {
75  return full_body.substr( m_started_at, m_size );
76  }
77 
79 
86  make_string_view( string_view_t full_body ) const
87  {
88  if( m_started_at >= full_body.size() ||
89  m_started_at + m_size > full_body.size() )
90  {
91  throw exception_t{
92  fmt::format( "unable to make a chunk (started_at:{}, size: {}) "
93  "from a body with length:{}",
95  m_size,
96  full_body.size() )
97  };
98  }
99 
100  return make_string_view_nonchecked( full_body );
101  }
102 };
103 
104 namespace impl
105 {
106 
107 //
108 // chunked_input_info_block_t
109 //
116 {
118  std::vector< chunk_info_t > m_chunks;
119 
121 
126 };
127 
128 } /* namespace impl */
129 
130 //
131 // chunked_input_info_t
132 //
143 {
146 
147 public:
149  chunked_input_info_t() = default;
151 
158  : m_info{ std::move(info) }
159  {}
160 
162 
166  std::size_t
167  chunk_count() const noexcept { return m_info.m_chunks.size(); }
168 
170 
176  const chunk_info_t &
177  chunk_at_nochecked( std::size_t index ) const noexcept
178  {
179  return m_info.m_chunks[ index ];
180  }
181 
183 
187  const chunk_info_t &
188  chunk_at( std::size_t index ) const
189  {
190  return m_info.m_chunks.at( index );
191  }
192 
194 
201  const auto &
202  chunks() const noexcept
203  {
204  return m_info.m_chunks;
205  }
206 
208 
214  const http_header_fields_t &
216  {
217  return m_info.m_trailing_fields;
218  }
219 };
220 
221 //
222 // chunked_input_info_unique_ptr_t
223 //
230  std::unique_ptr< chunked_input_info_t >;
231 
232 } /* namespace restinio */
233 
restinio::exception_t
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:421
restinio::impl::chunked_input_info_block_t
Bunch of data related to chunked input.
Definition: chunked_input_info.hpp:116
restinio::chunked_input_info_t::m_info
impl::chunked_input_info_block_t m_info
Actual data.
Definition: chunked_input_info.hpp:145
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::chunked_input_info_t::chunked_input_info_t
chunked_input_info_t()=default
Default constructor. Makes empty object.
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
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::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::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::m_size
std::size_t m_size
Definition: chunked_input_info.hpp:43
restinio::http_header_fields_t
Header fields map.
Definition: http_headers.hpp:703
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:118
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:167
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:202
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:125
restinio::chunk_info_t::m_started_at
std::size_t m_started_at
Definition: chunked_input_info.hpp:42
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:177
include_fmtlib.hpp
A special wrapper around fmtlib include files.
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:188
restinio::chunked_input_info_t
An information about chunks and trailing fields in the incoming request.
Definition: chunked_input_info.hpp:143
restinio
Definition: asio_include.hpp:21
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::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:215
exception.hpp
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:230
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:156
restinio::chunk_info_t
Information about one chunk in an incoming request with chunked encoding.
Definition: chunked_input_info.hpp:41
http_headers.hpp
const
#define const
Definition: zconf.h:230