Skip to content

Add support for multipart/mixed content type#1291

Open
hhaensel wants to merge 10 commits into
JuliaWeb:masterfrom
hhaensel:hh-multipart-mixed2
Open

Add support for multipart/mixed content type#1291
hhaensel wants to merge 10 commits into
JuliaWeb:masterfrom
hhaensel:hh-multipart-mixed2

Conversation

@hhaensel

@hhaensel hhaensel commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This PR is a port of the older #1100 with the help of Claude 4.5
It fixes #1101.

This commit adds comprehensive support for multipart/mixed content, commonly used for batch API requests (e.g., SharePoint, GraphQL).

Core functionality:

  • Added type field to Form struct to support :formdata and :mixed
  • Form constructor accepts type parameter (defaults to :formdata)
  • Form(Vector{Multipart}) constructor for multipart/mixed
  • Updated content_type() to return correct MIME type based on form type

Parsing enhancements:

  • Modified parsing to optionally skip Content-Disposition headers (not required for multipart/mixed per RFC2046)
  • Added parse_multipart() as generic parser for any multipart type
  • Added parse_multipart_mixed() convenience function
  • Support for type filtering in parsing functions

API additions:

  • Batch() convenience function for semantic batch request creation
  • Exported: parse_multipart, parse_multipart_mixed, Batch

Testing:

  • Comprehensive test suite in test/http_multipart_mixed.jl
  • 41 tests covering creation, parsing, round-trip, and edge cases

The implementation is adapted from the original work in commit 573fb62 but updated to work with HTTP v2 architecture where multipart functionality is consolidated in http_forms.jl.

This commit adds comprehensive support for multipart/mixed content,
commonly used for batch API requests (e.g., SharePoint, GraphQL).

Core functionality:
- Added `type` field to Form struct to support :formdata and :mixed
- Form constructor accepts type parameter (defaults to :formdata)
- Form(Vector{Multipart}) constructor for multipart/mixed
- Updated content_type() to return correct MIME type based on form type

Parsing enhancements:
- Modified parsing to optionally skip Content-Disposition headers
  (not required for multipart/mixed per RFC2046)
- Added parse_multipart() as generic parser for any multipart type
- Added parse_multipart_mixed() convenience function
- Support for type filtering in parsing functions

API additions:
- Batch() convenience function for semantic batch request creation
- Exported: parse_multipart, parse_multipart_mixed, Batch

Testing:
- Comprehensive test suite in test/http_multipart_mixed.jl
- 41 tests covering creation, parsing, round-trip, and edge cases

The implementation is adapted from the original work in commit
573fb62 but updated to work with
HTTP v2 architecture where multipart functionality is consolidated
in http_forms.jl.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.18310% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.33%. Comparing base (51f101a) to head (4b9ead5).
⚠️ Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
src/http_forms.jl 97.18% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1291      +/-   ##
==========================================
+ Coverage   84.60%   87.33%   +2.73%     
==========================================
  Files          28       29       +1     
  Lines       10787    11356     +569     
==========================================
+ Hits         9126     9918     +792     
+ Misses       1661     1438     -223     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hhaensel hhaensel marked this pull request as ready for review June 9, 2026 21:01
@hhaensel

Copy link
Copy Markdown
Contributor Author

@quinnj Just found some possible improvements, please don't merge yet

@hhaensel

Copy link
Copy Markdown
Contributor Author

@quinnj just review as is! The idea I had was not so good...

Comment thread src/http_forms.jl
Comment thread src/http_forms.jl Outdated
Comment thread src/http_forms.jl Outdated
@hhaensel

Copy link
Copy Markdown
Contributor Author

@quinnj just need feedback on my two open conversations.
I tend to revert the @assert change, it seems that @assert is quite common in HTTP

@hhaensel

Copy link
Copy Markdown
Contributor Author

Don't merge yet, I'm still adding an example ...

Extends parse_multipart_form(), parse_multipart(), and parse_multipart_mixed()
to accept Union{Request,Response}, enabling parsing of multipart responses from
external APIs (e.g., SharePoint batch operations, GraphQL batch queries).

Changes:
- Refactor to use Union{Request,Response} pattern (matches http_core.jl style)
- Unify body extraction into _message_body_bytes() helper
- Add comprehensive test coverage for Response parsing
- Include batch server example demonstrating multipart/mixed usage
- Update docstrings with jldoctest examples
- Fully backward compatible with existing Request API

All tests pass.
@hhaensel

Copy link
Copy Markdown
Contributor Author

I've added a multibatch example including server. It turned out that the parsing was needed for both Requests and Responses, so I decided to unify http_forms.jl accordingly. Here's what I did in detail

  • Refactor to use Union{Request,Response} pattern (matches http_core.jl style)
  • Rename helper _request_body_bytes() to `_message_body_bytes()
  • Add comprehensive Response parsing tests
  • Include batch server example demonstrating multipart/mixed usage
  • Update docstrings with jldoctest examples

This is all fully backward compatible with existing Request API

@hhaensel

Copy link
Copy Markdown
Contributor Author

@quinnj ready for final review :-)

@hhaensel

Copy link
Copy Markdown
Contributor Author

Found a bug in HTTP 2.3.0, it references VERSION in HTTP's scope for the public declarations. I fixed it here and also filed #1313

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.

Feature Request: Add handling of multipart/mixed messages

2 participants