32namespace multipart_body
71inline std::vector< string_view_t >
78 std::vector< string_view_t >
result;
158namespace parser_details
165constexpr char CR =
'\r';
166constexpr char LF =
'\n';
191 return from.fragment(
from.current_position() );
216 while( !
ch.m_eof &&
ch.m_ch !=
CR &&
ch.m_ch !=
LF )
224 from.current_position(),
256 using namespace parser_details;
262 token_p() >> to_lower() >> custom_consumer(
263 [](
auto &
f, std::string && v) {
264 f.name(std::move(v));
268 field_value_producer_t{} >> custom_consumer(
269 [](
auto &
f, std::string && v) {
270 f.value(std::move(v));
272 symbol(CR), symbol(LF)
273 ) >> custom_consumer(
275 to.add_field( std::move(v) );
279 symbol(CR), symbol(LF),
389namespace boundary_value_checkers
405 return (
ch >=
'0' &&
ch <=
'9')
406 || ((
ch >=
'A' &&
ch <=
'Z') || (
ch >=
'a' &&
ch <=
'z'))
456inline std::optional< enumeration_error_t >
459 using namespace impl::boundary_value_checkers;
461 if( value.size() >= 1u && value.size() <= 70u )
463 const std::size_t
last_index = value.size() - 1u;
465 if( !is_bchar( value[
i] ) )
494template<
typename Extra_Data >
507 restinio::http_field::content_type );
509 return make_unexpected(
514 const auto parse_result = hfp::content_type_value_t::try_parse(
517 return make_unexpected(
523 return make_unexpected(
529 return make_unexpected(
534 const auto boundary = hfp::find_first(
538 return make_unexpected(
567template<
typename Handler >
571 const std::vector< string_view_t > &
parts,
575 std::optional< enumeration_error_t > error;
598 return make_unexpected( *error );
606template<
typename,
typename = restinio::utils::metaprogramming::
void_t<> >
609template<
typename T >
616 decltype(std::declval<T>()(std::declval<parsed_part_t>()))
621 > :
public std::true_type
683template<
typename User_Type,
typename Handler >
707 impl::valid_handler_type< std::decay_t<Handler> >::value,
708 "Handler should be callable object, "
709 "should accept parsed_part_t by value, const or rvalue reference, "
710 "and should return handling_result_t" );
721 return make_unexpected(
726 std::forward<Handler>(
handler) );
729 return make_unexpected(
boundary.error() );
Utilities for parsing values of http-fields.
The class that implements "input stream".
A special class to be used as the top level clause in parser.
auto try_process(source_t &from)
Information about parsing error.
Stuff related to value of Content-Type HTTP-field.
An very small, simple and somewhat limited implementation of recursive-descent parser.
@ unexpected_eof
Unexpected end of input is encontered when some character expected.
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
constexpr bool is_bchar(char ch)
constexpr bool is_bcharnospace(char ch)
expected_t< std::size_t, enumeration_error_t > enumerate_parts_of_request_body(const std::vector< string_view_t > &parts, Handler &&handler)
A function that parses every part of a multipart body and calls a user-provided handler for every par...
auto make_parser()
A factory function for a parser of a part of multipart message.
handling_result_t
The result to be returned from user-provided handler of parts of multipart body.
@ stop_enumeration
Enumeration of parts should be stopped. All remaining parts of multipart body will be skipped....
@ terminate_enumeration
Enumeration of parts should be ignored. All remaining parts of multipart body will be skipped and the...
@ continue_enumeration
Enumeration of parts should be continued. If there is another part the user-provided handler will be ...
std::vector< string_view_t > split_multipart_body(string_view_t body, string_view_t boundary)
Helper function for spliting a multipart body into a serie of separate parts.
expected_t< parsed_part_t, restinio::easy_parser::parse_error_t > try_parse_part(string_view_t part)
Helper function for parsing content of one part of a multipart body.
std::optional< enumeration_error_t > check_boundary_value(string_view_t value)
A helper function for checking the validity of 'boundary' value.
enumeration_error_t
The result of an attempt to enumerate parts of a multipart body.
@ content_type_field_inappropriate_value
Content-Type field value parsed but doesn't contain an appropriate value. For example there can be me...
@ no_parts_found
No parts of a multipart body actually found.
@ illegal_boundary_value
Value of 'boundary' parameter is invalid (for example it contains some illegal characters).
@ content_type_field_not_found
Content-Type field is not found. If Content-Type is absent there is no way to detect 'boundary' param...
@ terminated_by_handler
Enumeration of parts was aborted by user-provided handler. This code is returned when user-provided h...
@ content_type_field_parse_error
Unable to parse Content-Type field value.
@ unexpected_error
Some unexpected error encountered during the enumeration.
expected_t< std::string, enumeration_error_t > detect_boundary_for_multipart_body(const generic_request_t< Extra_Data > &req, string_view_t expected_media_type, std::optional< string_view_t > expected_media_subtype)
Helper function for parsing Content-Type field and extracting the value of 'boundary' parameter.
expected_t< std::size_t, enumeration_error_t > enumerate_parts(const generic_request_t< User_Type > &req, Handler &&handler, string_view_t expected_media_type=string_view_t{ "multipart" }, std::optional< string_view_t > expected_media_subtype=std::nullopt)
A helper function for enumeration of parts of a multipart body.
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
nonstd::expected< T, E > expected_t
Various string-related algorithms.
Helpers for caseless comparison of strings.
A special base class to be used with producers.
A special producer that consumes the whole remaining content from the input stream.
expected_t< string_view_t, easy_parser::parse_error_t > try_parse(easy_parser::impl::source_t &from) const noexcept
A special producer that consumes the rest of the current line in the input stream until CR/LF will be...
expected_t< std::string, easy_parser::parse_error_t > try_parse(easy_parser::impl::source_t &from) const
A description of parsed content of one part of a multipart body.
http_header_fields_t fields
HTTP-fields local for that part.
string_view_t body
The body of that part.