2
3
6
7
8
9
10
14#include <restinio/helpers/http_field_parsers/content-type.hpp>
15#include <restinio/helpers/http_field_parsers/content-disposition.hpp>
16#include <restinio/helpers/multipart_body.hpp>
18#include <restinio/http_headers.hpp>
19#include <restinio/request_handler.hpp>
20#include <restinio/expected.hpp>
34
35
36
37
38
126
127
128
129
130
137
138
139
140
141
142
143
144
145
150
151
152
160
161
162
163
164
165
166
167
168
172
173
174
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
226 const auto disposition_field = parsed_part.fields.opt_value_of(
228 if( !disposition_field )
233 const auto parsed_disposition = hfp::content_disposition_value_t::
234 try_parse( *disposition_field );
235 if( !parsed_disposition )
236 return make_unexpected(
238 if(
"form-data" != parsed_disposition->value )
241 const auto name = hfp::find_first(
242 parsed_disposition->parameters,
"name" );
244 return make_unexpected(
246 const auto expected_to_optional = [](
auto expected ) {
248 std::optional< std::string >{ std::string{
252 : std::optional< std::string >{};
255 auto filename_star = expected_to_optional( hfp::find_first(
256 parsed_disposition->parameters,
"filename*" ) );
257 auto filename = expected_to_optional( hfp::find_first(
258 parsed_disposition->parameters,
"filename" ) );
261 if( !filename_star && !filename )
265 std::move( parsed_part.fields ),
267 std::string{ name->data(), name->size() },
268 std::move(filename_star),
282template<
typename T >
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358template<
typename Extra_Data,
typename Handler >
367 string_view_t expected_media_type =
string_view_t{
"multipart"},
369 string_view_t expected_media_subtype =
string_view_t{
"form-data"} )
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 };
381 [&handler, &files_found, &error]
384 auto part_description = analyze_part( std::move(part) );
385 if( part_description )
389 return handler( std::move(*part_description) );
392 part_description.error() )
398 error = part_description.error();
403 expected_media_subtype );
406 return make_unexpected( *error );
408 return make_unexpected(
constexpr enumeration_error_t translate_enumeration_error(restinio::multipart_body::enumeration_error_t original)
Helper function for conversion from one enumeration_error to another.
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 ...
restinio::multipart_body::handling_result_t handling_result_t
The result to be returned from user-provided handler of parts of multipart body.
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.
handling_result_t
The result to be returned from user-provided handler of parts of multipart body.
@ 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 ...
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.
http_field_t http_field
Helper alies to omitt _t suffix.
A description of one part with an uploaded file.
http_header_fields_t fields
HTTP-fields local for that part.
std::optional< std::string > filename
The value of Content-Disposition's 'filename' parameter.
std::string name
The value of Content-Disposition's 'name' parameter.
string_view_t body
The body of that part.
std::optional< std::string > filename_star
The value of Content-Disposition's 'filename*' parameter.
A description of parsed content of one part of a multipart body.