RESTinio
|
Namespaces | |
namespace | impl |
Classes | |
struct | parsed_part_t |
A description of parsed content of one part of a multipart body. More... | |
Enumerations | |
enum class | handling_result_t { continue_enumeration , stop_enumeration , terminate_enumeration } |
The result to be returned from user-provided handler of parts of multipart body. More... | |
enum class | enumeration_error_t { content_type_field_not_found , content_type_field_parse_error , content_type_field_inappropriate_value , illegal_boundary_value , no_parts_found , terminated_by_handler , unexpected_error } |
The result of an attempt to enumerate parts of a multipart body. More... | |
Functions | |
RESTINIO_NODISCARD 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. More... | |
RESTINIO_NODISCARD 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. More... | |
RESTINIO_NODISCARD optional_t< enumeration_error_t > | check_boundary_value (string_view_t value) |
A helper function for checking the validity of 'boundary' value. More... | |
template<typename Extra_Data > | |
RESTINIO_NODISCARD 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, optional_t< string_view_t > expected_media_subtype) |
Helper function for parsing Content-Type field and extracting the value of 'boundary' parameter. More... | |
template<typename User_Type , typename Handler > | |
RESTINIO_NODISCARD 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" }, optional_t< string_view_t > expected_media_subtype=nullopt) |
A helper function for enumeration of parts of a multipart body. More... | |
|
strong |
The result of an attempt to enumerate parts of a multipart body.
Enumerator | |
---|---|
content_type_field_not_found | Content-Type field is not found. If Content-Type is absent there is no way to detect 'boundary' parameter. |
content_type_field_parse_error | Unable to parse Content-Type field value. |
content_type_field_inappropriate_value | Content-Type field value parsed but doesn't contain an appropriate value. For example there can be media-type different from 'multipart' or 'boundary' parameter can be absent. |
illegal_boundary_value | Value of 'boundary' parameter is invalid (for example it contains some illegal characters). |
no_parts_found | No parts of a multipart body actually found. |
terminated_by_handler | Enumeration of parts was aborted by user-provided handler. This code is returned when user-provided handler returns handling_result_t::terminate_enumeration. |
unexpected_error | Some unexpected error encountered during the enumeration. |
Definition at line 361 of file multipart_body.hpp.
|
strong |
The result to be returned from user-provided handler of parts of multipart body.
Definition at line 337 of file multipart_body.hpp.
|
inline |
A helper function for checking the validity of 'boundary' value.
The allowed format for 'boundary' value is defined here: https://tools.ietf.org/html/rfc2046
boundary := 0*69<bchars> bcharsnospace bchars := bcharsnospace / " " bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" / "+" / "_" / "," / "-" / "." / "/" / ":" / "=" / "?"
Definition at line 457 of file multipart_body.hpp.
RESTINIO_NODISCARD expected_t< std::string, enumeration_error_t > restinio::multipart_body::detect_boundary_for_multipart_body | ( | const generic_request_t< Extra_Data > & | req, |
string_view_t | expected_media_type, | ||
optional_t< string_view_t > | expected_media_subtype | ||
) |
Helper function for parsing Content-Type field and extracting the value of 'boundary' parameter.
It finds Content-Type field, then parses it, then checks the value of media-type, then finds 'boundary' parameter, the checks the validity of 'boundary' value and then adds two leading hypens to the value of 'boundary' parameter.
The returned value (if there is no error) can be used for spliting a multipart body to separate parts.
Definition at line 497 of file multipart_body.hpp.
RESTINIO_NODISCARD expected_t< std::size_t, enumeration_error_t > restinio::multipart_body::enumerate_parts | ( | const generic_request_t< User_Type > & | req, |
Handler && | handler, | ||
string_view_t | expected_media_type = string_view_t{ "multipart" } , |
||
optional_t< string_view_t > | expected_media_subtype = nullopt |
||
) |
A helper function for enumeration of parts of a multipart body.
This function:
Enumeration stops if handler returns handling_result_t::stop_enumeration or handling_result_t::terminate_enumeration. If handler returns handling_result_t::terminate_enumeration the enumerate_parts() returns enumeration_error_t::terminated_by_handler error code.
A handler passed as handler argument should be a function or lambda/functor with one of the following formats:
Note that enumerate_part() passes parsed_part_t instance to handler as rvalue reference. And this reference will be invalidaded after the return from handler.
Usage example:
req | The request to be handled. |
handler | The handler to be called for every parsed part. |
expected_media_type | The expected value of 'type' part of 'media-type' from Content-Type. If 'type' part is not equal to expected_media_type then enumeration won't be performed. |
expected_media_subtype | The optional expected value of 'subtype' part of 'media-type' from Content-Type. If expected_media_subtype is specified and missmatch with 'subtype' part then enumeration won't be performed. |
Definition at line 686 of file multipart_body.hpp.
|
inline |
Helper function for spliting a multipart body into a serie of separate parts.
Usage example:
Definition at line 72 of file multipart_body.hpp.
RESTINIO_NODISCARD expected_t< parsed_part_t, restinio::easy_parser::parse_error_t > restinio::multipart_body::try_parse_part | ( | string_view_t | part | ) |
Helper function for parsing content of one part of a multipart body.
This function is intended to be used with split_multipart_body():
Definition at line 315 of file multipart_body.hpp.