@@ -211,26 +211,20 @@ using Progress = std::function<bool(uint64_t current, uint64_t total)>;
211
211
struct Response ;
212
212
using ResponseHandler = std::function<bool (const Response &response)>;
213
213
214
- struct MultipartFile {
215
- std::string filename;
216
- std::string content_type;
217
- std::string content;
218
- };
219
- using MultipartFiles = std::multimap<std::string, MultipartFile>;
220
-
221
214
struct MultipartFormData {
222
215
std::string name;
223
216
std::string content;
224
217
std::string filename;
225
218
std::string content_type;
226
219
};
227
220
using MultipartFormDataItems = std::vector<MultipartFormData>;
221
+ using MultipartFormDataMap = std::multimap<std::string, MultipartFormData>;
228
222
229
223
using ContentReceiver =
230
224
std::function<bool (const char *data, size_t data_length)>;
231
225
232
226
using MultipartContentHeader =
233
- std::function<bool (const std::string &name, const MultipartFile &file)>;
227
+ std::function<bool (const std::string &name, const MultipartFormData &file)>;
234
228
235
229
using MultipartContentReceiver =
236
230
std::function<bool (const std::string& name, const char *data, size_t data_length)>;
@@ -268,7 +262,7 @@ struct Request {
268
262
std::string version;
269
263
std::string target;
270
264
Params params;
271
- MultipartFiles files;
265
+ MultipartFormDataMap files;
272
266
Ranges ranges;
273
267
Match matches;
274
268
@@ -295,7 +289,7 @@ struct Request {
295
289
bool is_multipart_form_data () const ;
296
290
297
291
bool has_file (const char *key) const ;
298
- MultipartFile get_file_value (const char *key) const ;
292
+ MultipartFormData get_file_value (const char *key) const ;
299
293
300
294
// private members...
301
295
size_t content_length;
@@ -2015,6 +2009,7 @@ class MultipartFormDataParser {
2015
2009
case 2 : { // Headers
2016
2010
auto pos = buf_.find (crlf_);
2017
2011
while (pos != std::string::npos) {
2012
+ // Empty line
2018
2013
if (pos == 0 ) {
2019
2014
if (!header_callback (name_, file_)) {
2020
2015
is_valid_ = false ;
@@ -2034,6 +2029,7 @@ class MultipartFormDataParser {
2034
2029
file_.content_type = m[1 ];
2035
2030
} else if (std::regex_match (header, m, re_content_disposition)) {
2036
2031
name_ = m[1 ];
2032
+ file_.name = name_;
2037
2033
file_.filename = m[2 ];
2038
2034
}
2039
2035
}
@@ -2137,7 +2133,7 @@ class MultipartFormDataParser {
2137
2133
size_t is_done_ = false ;
2138
2134
size_t off_ = 0 ;
2139
2135
std::string name_;
2140
- MultipartFile file_;
2136
+ MultipartFormData file_;
2141
2137
};
2142
2138
2143
2139
inline std::string to_lower (const char *beg, const char *end) {
@@ -2512,10 +2508,10 @@ inline bool Request::has_file(const char *key) const {
2512
2508
return files.find (key) != files.end ();
2513
2509
}
2514
2510
2515
- inline MultipartFile Request::get_file_value (const char *key) const {
2511
+ inline MultipartFormData Request::get_file_value (const char *key) const {
2516
2512
auto it = files.find (key);
2517
2513
if (it != files.end ()) { return it->second ; }
2518
- return MultipartFile ();
2514
+ return MultipartFormData ();
2519
2515
}
2520
2516
2521
2517
// Response implementation
@@ -2985,7 +2981,7 @@ inline bool Server::read_content(Stream &strm, bool last_connection,
2985
2981
return true ;
2986
2982
},
2987
2983
// Multipart
2988
- [&](const std::string &name, const MultipartFile &file) {
2984
+ [&](const std::string &name, const MultipartFormData &file) {
2989
2985
req.files .emplace (name, file);
2990
2986
return true ;
2991
2987
},
0 commit comments