1 #ifndef XXHR_MULTIPART_H
2 #define XXHR_MULTIPART_H
5 #include <initializer_list>
10 #include "defines.hpp"
18 template <
typename StringType>
19 explicit File(StringType&& filepath)
20 : filepath{XXHR_FWD(filepath)} {}
28 typedef const unsigned char* data_t;
30 template <
typename Iterator,
typename StringType>
31 explicit Buffer(Iterator begin, Iterator end, StringType&& filename)
32 : data{
reinterpret_cast<data_t
>(&(*begin))},
33 datalen{
static_cast<unsigned long>(std::distance(begin, end))},
34 filename{XXHR_FWD(filename)} {
35 is_random_access_iterator(begin, end);
36 static_assert(
sizeof(*begin) == 1,
"only byte buffers can be used");
39 template <
typename Iterator>
40 typename std::enable_if<std::is_same<typename std::iterator_traits<Iterator>::iterator_category,
41 std::random_access_iterator_tag>::value>::type
42 is_random_access_iterator(Iterator begin, Iterator end) {}
45 unsigned long datalen;
53 Part(
const std::string& name,
const std::string& value,
const std::string& content_type = {})
54 : name{name}, value{value}, content_type{content_type}, is_file{
false},
56 Part(
const std::string& name,
const std::int32_t& value,
const std::string& content_type = {})
57 : name{name}, value{std::to_string(value)}, content_type{content_type}, is_file{
false},
59 Part(
const std::string& name,
const File& file,
const std::string& content_type = {})
60 : name{name}, value{file.filepath}, content_type{content_type}, is_file{
true},
62 Part(
const std::string& name,
const Buffer& buffer,
const std::string& content_type = {})
63 : name{name}, value{buffer.filename}, content_type{content_type}, data{buffer.data},
64 datalen{buffer.datalen}, is_file{
false}, is_buffer{
true} {}
68 std::string content_type;
70 unsigned long datalen;
85 Multipart(
const std::initializer_list<Part>& parts) : parts{parts} {}
87 std::vector<Part> parts;