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

Merged
merged 8 commits into from
Jun 9, 2025
Merged

Conversation

kwach
Copy link
Contributor

@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.
kwach added 2 commits June 8, 2025 13:57
Improves header parsing by using a dedicated parsing function,
resulting in cleaner and more robust code.

This change also adds error handling during header parsing,
returning an error and marking the request as invalid
if parsing fails.
@yhirose
Copy link
Owner

yhirose commented Jun 8, 2025

@kwach could you please run clang-format? (You don't have to worry about the 'abidiff/abi' error.
https://github.com/yhirose/cpp-httplib/actions/runs/15518234423/job/43688499197?pr=2152

@kwach kwach force-pushed the feature/multipart-headers branch from cdd6f30 to 8b70d51 Compare June 8, 2025 14:08
@kwach
Copy link
Contributor Author

kwach commented Jun 8, 2025

@kwach could you please run clang-format? (You don't have to worry about the 'abidiff/abi' error. https://github.com/yhirose/cpp-httplib/actions/runs/15518234423/job/43688499197?pr=2152

heh, ok. I've enabled workflows on my fork and now it passes. I'm just learnig about workflows, sorry :D

ASSERT_EQ("CustomValue", customHeader->second);
ASSERT_TRUE(headers.find("X-Test") == headers.end()); // text1 header

handled = true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why handled is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reused code from the MultipartFormDataTest

Copy link
Contributor Author

@kwach kwach Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then there is

ASSERT_TRUE(handled);

in

auto se = detail::scope_exit([&] {...}

kwach added 2 commits June 9, 2025 15:42
Renames the `customHeader` variable to `custom_header` for improved code readability and consistency.
@kwach
Copy link
Contributor Author

kwach commented Jun 9, 2025

[==========] 365 tests from 88 test suites ran. (272323 ms total)
[  PASSED  ] 365 tests.

  YOU HAVE 2 DISABLED TESTS

@yhirose yhirose merged commit fd8da4d into yhirose:master Jun 9, 2025
8 of 9 checks passed
@yhirose
Copy link
Owner

yhirose commented Jun 9, 2025

Thanks for your fine contribution!

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