|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
Streaming parser for multipart/form-data. More...
#include <MultipartStreamParser.hpp>

Public Types | |
| using | OnFieldCallback = std::function< void(const std::string &name, const std::string &value)> |
| using | OnFileCallback = std::function< void(const std::string &name, const std::string &filename, const std::string &content_type, const std::string &tmp_filepath)> |
filename is chosen by the client: never use it as a path. | |
Public Member Functions | |
| MultipartStreamParser (const std::string &boundary, OnFieldCallback on_field, OnFileCallback on_file, MultipartLimits limits={}) | |
| Constructs a new MultipartStreamParser. | |
| ~MultipartStreamParser () | |
| MultipartStreamParser (const MultipartStreamParser &)=delete | |
| MultipartStreamParser & | operator= (const MultipartStreamParser &)=delete |
| bool | feed (std::string_view chunk) |
| Feeds a chunk of data into the parser. | |
| void | end () |
| Signals the end of the input stream. | |
| bool | failed () const |
| True if a limit was exceeded or a file could not be written. | |
| const std::string & | error () const |
| bool | complete () const |
Private Types | |
| enum class | State { FINDING_BOUNDARY , READING_HEADERS , READING_BODY } |
Private Member Functions | |
| void | process_buffer () |
| void | parse_headers (std::string_view headers) |
| bool | open_temp_file () |
| bool | append_body (std::string_view data) |
| void | close_current_part () |
| void | discard_current_part () |
| void | fail (const std::string &reason) |
Private Attributes | |
| std::string | boundary_ |
| std::string | dash_boundary_ |
| OnFieldCallback | on_field_ |
| OnFileCallback | on_file_ |
| MultipartLimits | limits_ |
| State | state_ = State::FINDING_BOUNDARY |
| std::string | buffer_ |
| std::string | current_name_ |
| std::string | current_filename_ |
| std::string | current_content_type_ |
| std::string | current_field_value_ |
| int | current_fd_ = -1 |
| size_t | current_size_ = 0 |
| std::string | current_tmp_filepath_ |
| size_t | total_size_ = 0 |
| size_t | parts_ = 0 |
| bool | failed_ = false |
| bool | finished_ = false |
| std::string | error_ |
Streaming parser for multipart/form-data.
Files are written to unpredictable names, created exclusively with owner-only permissions. A file passed to the OnFileCallback belongs to the application, which should move or delete it; files of parts that did not complete (malformed input, a limit, or the parser being destroyed) are deleted by the parser and never reported.
| using orbit::http::MultipartStreamParser::OnFieldCallback = std::function<void(const std::string& name, const std::string& value)> |
| using orbit::http::MultipartStreamParser::OnFileCallback = std::function<void(const std::string& name, const std::string& filename, const std::string& content_type, const std::string& tmp_filepath)> |
filename is chosen by the client: never use it as a path.
|
strongprivate |
| orbit::http::MultipartStreamParser::MultipartStreamParser | ( | const std::string & | boundary, |
| OnFieldCallback | on_field, | ||
| OnFileCallback | on_file, | ||
| MultipartLimits | limits = {} |
||
| ) |
Constructs a new MultipartStreamParser.
| boundary | The boundary string from the Content-Type header. |
| on_field | Callback invoked when a standard form field is parsed. |
| on_file | Callback invoked when a file is parsed and saved to a temporary location. |
| limits | Size limits and upload directory. |
| orbit::http::MultipartStreamParser::~MultipartStreamParser | ( | ) |
|
delete |
|
private |
|
private |
|
inline |
True once the closing boundary has been seen without a failure. A body that ended before it (a truncated upload) is not complete.
|
private |
| void orbit::http::MultipartStreamParser::end | ( | ) |
Signals the end of the input stream.
|
inline |
|
private |
|
inline |
True if a limit was exceeded or a file could not be written.
| bool orbit::http::MultipartStreamParser::feed | ( | std::string_view | chunk | ) |
Feeds a chunk of data into the parser.
| chunk | The data chunk to parse. |
|
private |
|
delete |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |