| 1 | #ifndef CPR_MULTIPART_H |
| 2 | #define CPR_MULTIPART_H |
| 3 | |
| 4 | #include <cstdint> |
| 5 | #include <initializer_list> |
| 6 | #include <string> |
| 7 | #include <type_traits> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "buffer.h" |
| 11 | #include "file.h" |
| 12 | |
| 13 | namespace cpr { |
| 14 | |
| 15 | struct Part { |
| 16 | Part(const std::string& p_name, const std::string& p_value, const std::string& p_content_type = {}) : name{p_name}, value{p_value}, content_type{p_content_type}, is_file{false}, is_buffer{false} {} |
| 17 | Part(const std::string& p_name, const std::int32_t& p_value, const std::string& p_content_type = {}) : name{p_name}, value{std::to_string(val: p_value)}, content_type{p_content_type}, is_file{false}, is_buffer{false} {} |
| 18 | Part(const std::string& p_name, const Files& p_files, const std::string& p_content_type = {}) : name{p_name}, content_type{p_content_type}, is_file{true}, is_buffer{false}, files{p_files} {} |
| 19 | Part(const std::string& p_name, Files&& p_files, const std::string& p_content_type = {}) : name{p_name}, content_type{p_content_type}, is_file{true}, is_buffer{false}, files{p_files} {} |
| 20 | Part(const std::string& p_name, const Buffer& buffer, const std::string& p_content_type = {}) : name{p_name}, value{buffer.filename.string()}, content_type{p_content_type}, data{buffer.data}, datalen{buffer.datalen}, is_file{false}, is_buffer{true} {} |
| 21 | |
| 22 | std::string name; |
| 23 | // We don't use fs::path here, as this leads to problems using windows |
| 24 | std::string value; |
| 25 | std::string content_type; |
| 26 | Buffer::data_t data{nullptr}; |
| 27 | size_t datalen{0}; |
| 28 | bool is_file; |
| 29 | bool is_buffer; |
| 30 | |
| 31 | Files files; |
| 32 | }; |
| 33 | |
| 34 | class Multipart { |
| 35 | public: |
| 36 | Multipart(const std::initializer_list<Part>& parts); |
| 37 | |
| 38 | std::vector<Part> parts; |
| 39 | }; |
| 40 | |
| 41 | } // namespace cpr |
| 42 | |
| 43 | #endif |
| 44 | |