-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Feature/multipart headers #2152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
kwach
commented
Jun 6, 2025
- feature: additional field: header - providing access to headers per form-data part
- UT test provided
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.
Verifies the correct retrieval of headers from multipart form data file parts. Ensures that custom and content-related headers are accessible and parsed as expected.
Uses `gtest_discover_tests` to automatically find and run tests, simplifying test maintenance and improving discoverability.
@@ -29,6 +29,7 @@ find_package(CURL REQUIRED) | |||
add_executable(httplib-test test.cc include_httplib.cc $<$<BOOL:${WIN32}>:include_windows_h.cc>) | |||
target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>") | |||
target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main CURL::libcurl) | |||
include(GoogleTest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sum01 @jimmy-park is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is redundant because the GoogleTest module is already included in find_package(GTest)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kwach could you please remove the line?
@@ -5045,6 +5046,14 @@ class MultipartFormDataParser { | |||
return false; | |||
} | |||
|
|||
// split header string by ':' and emplace space trimmed into headers map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to parse the header text yourself. You can replace the code from line no 5043 through 5047 with the following code, so that you can avoid the extra parsing.
if (!parse_header(
header.data(), header.data() + header.size(),
[&](const std::string &key, const std::string &val) {
file_.headers.emplace(key, val);
})) {
is_valid_ = false;
return false;
}