91 dest result = dest::unexpected_error;
95 case source::content_type_field_not_found:
96 result = dest::content_type_field_not_found;
break;
98 case source::content_type_field_parse_error:
99 result = dest::content_type_field_parse_error;
break;
101 case source::content_type_field_inappropriate_value:
102 result = dest::content_type_field_inappropriate_value;
break;
104 case source::illegal_boundary_value:
105 result = dest::illegal_boundary_value;
break;
107 case source::no_parts_found:
108 result = dest::no_parts_found;
break;
110 case source::terminated_by_handler:
111 result = dest::terminated_by_handler;
break;
113 case source::unexpected_error:
227 restinio::http_field::content_disposition );
228 if( !disposition_field )
235 if( !parsed_disposition )
236 return make_unexpected(
238 if(
"form-data" != parsed_disposition->value )
242 parsed_disposition->parameters,
"name" );
244 return make_unexpected(
246 const auto expected_to_optional = [](
auto expected ) {
256 parsed_disposition->parameters,
"filename*" ) );
258 parsed_disposition->parameters,
"filename" ) );
261 if( !filename_star && !filename )
267 std::string{ name->data(), name->size() },
279template<
typename,
typename = restinio::utils::metaprogramming::
void_t<> >
282template<
typename T >
289 decltype(std::declval<T>()(std::declval<part_description_t>()))
358template<
typename Extra_Data,
typename Handler >
372 impl::valid_handler_type< std::decay_t<Handler> >::value,
373 "Handler should be callable object, "
374 "should accept part_description_t by value, const or rvalue reference, "
375 "and should return handling_result_t" );
377 std::size_t files_found{ 0u };
378 optional_t< enumeration_error_t > error;
381 [&handler, &files_found, &error]
385 if( part_description )
389 return handler(
std::move(*part_description) );
392 part_description.error() )
398 error = part_description.error();
399 return handling_result_t::terminate_enumeration;
403 expected_media_subtype );
406 return make_unexpected( *error );
408 return make_unexpected(
#define RESTINIO_NODISCARD
Stuff related to value of Content-Disposition HTTP-field.
Stuff related to value of Content-Type HTTP-field.
Various tools for working with multipart bodies.
bool_constant< false > false_type
bool_constant< true > true_type
RESTINIO_NODISCARD expected_t< typename Producer::result_type, parse_error_t > try_parse(string_view_t from, Producer producer)
Perform the parsing of the specified content by using specified value producer.
RESTINIO_NODISCARD constexpr enumeration_error_t translate_enumeration_error(restinio::multipart_body::enumeration_error_t original)
Helper function for conversion from one enumeration_error to another.
RESTINIO_NODISCARD expected_t< part_description_t, enumeration_error_t > analyze_part(restinio::multipart_body::parsed_part_t parsed_part)
Helper function for analyzing an already parsed part of a multipart body for presence of an uploaded ...
expected_t< std::size_t, enumeration_error_t > enumerate_parts_with_files(const generic_request_t< Extra_Data > &req, Handler &&handler, string_view_t expected_media_type=string_view_t{"multipart"}, string_view_t expected_media_subtype=string_view_t{"form-data"})
A helper function for enumeration of parts of a multipart body those contain uploaded files.
enumeration_error_t
The result of an attempt to enumerate parts of a multipart body that contains uploaded file.
@ content_type_field_inappropriate_value
Content-Type field value parsed but doesn't contain an appropriate value. For example there can be me...
@ no_files_found
No files found in the current part. For example, there is no Content-Disposition field for that part,...
@ 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.
@ content_disposition_field_inappropriate_value
Content-Disposition field value parsed but doesn't contain an appropriate value. For example,...
@ unexpected_error
Some unexpected error encountered during the enumeration.
@ content_disposition_field_parse_error
Unable to parse Content-Disposition field.
RESTINIO_NODISCARD expected_t< string_view_t, not_found_t > find_first(const parameter_with_mandatory_value_container_t &where, string_view_t what)
A helper function to find the first occurence of a parameter with the specified value.
handling_result_t
The result to be returned from user-provided handler of parts of multipart body.
@ continue_enumeration
Enumeration of parts should be continued. If there is another part the user-provided handler will be ...
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.
enumeration_error_t
The result of an attempt to enumerate parts of a multipart body.
nonstd::string_view string_view_t
nonstd::expected< T, E > expected_t
A description of one part with an uploaded file.
http_header_fields_t fields
HTTP-fields local for that part.
optional_t< std::string > filename
The value of Content-Disposition's 'filename' parameter.
std::string name
The value of Content-Disposition's 'name' parameter.
optional_t< std::string > filename_star
The value of Content-Disposition's 'filename*' parameter.
string_view_t body
The body of that part.
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.