Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kwach
Copy link

@kwach kwach commented Jun 6, 2025

  • feature: additional field: header - providing access to headers per form-data part
  • UT test provided
Note: Google Test filter = MultipartFormDataTest.AccessPartHeaders
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from MultipartFormDataTest
[ RUN      ] MultipartFormDataTest.AccessPartHeaders
[       OK ] MultipartFormDataTest.AccessPartHeaders (1004 ms)
[----------] 1 test from MultipartFormDataTest (1004 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (1004 ms total)
[  PASSED  ] 1 test.

kwach added 3 commits June 6, 2025 14:50
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)
Copy link
Owner

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?

Copy link
Contributor

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).

https://github.com/Kitware/CMake/blob/3bca7bca7b716ad0a618071d8052fbf2d9e4ad21/Modules/FindGTest.cmake#L242

Copy link
Owner

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
Copy link
Owner

@yhirose yhirose Jun 6, 2025

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;
          }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants