Skip to content

Commit 320c64f

Browse files
committed
Adds headers to multipart form data
Adds a `headers` field to the `MultipartFormData` struct. Populates this field by parsing headers from the multipart form data. This allows access to specific headers associated with each form data part.
1 parent 365cbe3 commit 320c64f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

httplib.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ struct MultipartFormData {
544544
std::string content;
545545
std::string filename;
546546
std::string content_type;
547+
Headers headers;
547548
};
548549
using MultipartFormDataItems = std::vector<MultipartFormData>;
549550
using MultipartFormDataMap = std::multimap<std::string, MultipartFormData>;
@@ -5045,6 +5046,14 @@ class MultipartFormDataParser {
50455046
return false;
50465047
}
50475048

5049+
// split header string by ':' and emplace space trimmed into headers map
5050+
auto colon_pos = header.find(':');
5051+
if (colon_pos != std::string::npos) {
5052+
auto key = trim_copy(header.substr(0, colon_pos));
5053+
auto val = trim_copy(header.substr(colon_pos + 1));
5054+
file_.headers.emplace(key, val);
5055+
}
5056+
50485057
constexpr const char header_content_type[] = "Content-Type:";
50495058

50505059
if (start_with_case_ignore(header, header_content_type)) {
@@ -5144,6 +5153,7 @@ class MultipartFormDataParser {
51445153
file_.name.clear();
51455154
file_.filename.clear();
51465155
file_.content_type.clear();
5156+
file_.headers.clear();
51475157
}
51485158

51495159
bool start_with_case_ignore(const std::string &a, const char *b) const {

0 commit comments

Comments
 (0)