44 using OnFieldCallback = std::function<void(
const std::string& name,
const std::string& value)>;
46 using OnFileCallback = std::function<void(
const std::string& name,
const std::string& filename,
const std::string& content_type,
const std::string& tmp_filepath)>;
67 bool feed(std::string_view chunk);
116 void fail(
const std::string& reason);
Streaming parser for multipart/form-data.
Definition MultipartStreamParser.hpp:42
State state_
Definition MultipartStreamParser.hpp:94
std::string current_filename_
Definition MultipartStreamParser.hpp:98
size_t total_size_
Definition MultipartStreamParser.hpp:104
bool failed_
Definition MultipartStreamParser.hpp:106
const std::string & error() const
Definition MultipartStreamParser.hpp:76
MultipartLimits limits_
Definition MultipartStreamParser.hpp:86
std::string buffer_
Definition MultipartStreamParser.hpp:95
OnFieldCallback on_field_
Definition MultipartStreamParser.hpp:84
void close_current_part()
std::string current_name_
Definition MultipartStreamParser.hpp:97
void parse_headers(std::string_view headers)
bool complete() const
Definition MultipartStreamParser.hpp:79
std::string current_content_type_
Definition MultipartStreamParser.hpp:99
std::string dash_boundary_
Definition MultipartStreamParser.hpp:83
State
Definition MultipartStreamParser.hpp:88
void fail(const std::string &reason)
std::string current_field_value_
Definition MultipartStreamParser.hpp:100
std::function< void(const std::string &name, const std::string &value)> OnFieldCallback
Definition MultipartStreamParser.hpp:44
size_t current_size_
Definition MultipartStreamParser.hpp:102
bool finished_
Definition MultipartStreamParser.hpp:107
void discard_current_part()
std::string current_tmp_filepath_
Definition MultipartStreamParser.hpp:103
bool feed(std::string_view chunk)
Feeds a chunk of data into the parser.
MultipartStreamParser(const std::string &boundary, OnFieldCallback on_field, OnFileCallback on_file, MultipartLimits limits={})
Constructs a new MultipartStreamParser.
size_t parts_
Definition MultipartStreamParser.hpp:105
bool failed() const
True if a limit was exceeded or a file could not be written.
Definition MultipartStreamParser.hpp:75
int current_fd_
Definition MultipartStreamParser.hpp:101
std::string error_
Definition MultipartStreamParser.hpp:108
std::string boundary_
Definition MultipartStreamParser.hpp:82
std::function< void(const std::string &name, const std::string &filename, const std::string &content_type, const std::string &tmp_filepath)> OnFileCallback
filename is chosen by the client: never use it as a path.
Definition MultipartStreamParser.hpp:46
MultipartStreamParser & operator=(const MultipartStreamParser &)=delete
OnFileCallback on_file_
Definition MultipartStreamParser.hpp:85
void end()
Signals the end of the input stream.
bool append_body(std::string_view data)
MultipartStreamParser(const MultipartStreamParser &)=delete
std::string multipart_boundary(std::string_view content_type)
Extracts the boundary parameter from a multipart Content-Type value, e.g. multipart/form-data; bounda...
Limits for MultipartStreamParser. Exceeding one fails the parse (see MultipartStreamParser::failed())...
Definition MultipartStreamParser.hpp:14
size_t max_file_size
Per uploaded file.
Definition MultipartStreamParser.hpp:15
size_t max_field_size
Per non-file field (kept in memory)
Definition MultipartStreamParser.hpp:16
std::string upload_dir
Definition MultipartStreamParser.hpp:21
size_t max_parts
Definition MultipartStreamParser.hpp:18
size_t max_total_size
Whole body.
Definition MultipartStreamParser.hpp:17