Skip to content

fix(binding): support multipart/mixed form parsing (#2547)#4684

Draft
ljluestc wants to merge 1 commit into
gin-gonic:masterfrom
ljluestc:private/fix-issue-2547-multipart-mixed
Draft

fix(binding): support multipart/mixed form parsing (#2547)#4684
ljluestc wants to merge 1 commit into
gin-gonic:masterfrom
ljluestc:private/fix-issue-2547-multipart-mixed

Conversation

@ljluestc
Copy link
Copy Markdown

变更内容

1) 新增 multipart/mixed MIME 常量与默认绑定映射

  • binding 层新增 MIMEMultipartMixed = "multipart/mixed"
  • binding.Default(...)multipart/mixed 返回 FormMultipart
  • gin 包导出同名常量,保持与现有 MIME 常量暴露方式一致

2) 引入 multipart 解析兜底逻辑

新增统一辅助函数 parseMultipartForm(req, maxMemory)(分别在 binding 包与 gin 包):

  • 先尝试 req.ParseMultipartForm(maxMemory)
  • 若错误为 ErrNotMultipart,且 Content-Typemultipart/mixed
    • 改用 req.MultipartReader().ReadForm(maxMemory) 解析
    • 回填 req.MultipartForm
    • 同步回填 req.PostFormreq.Form,保证后续取值路径兼容

@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

❌ Patch coverage is 62.71186% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.71%. Comparing base (3dc1cd6) to head (0cf6c87).
⚠️ Report is 276 commits behind head on master.

Files with missing lines Patch % Lines
multipart_form.go 53.84% 7 Missing and 5 partials ⚠️
binding/multipart_form.go 61.53% 6 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4684      +/-   ##
==========================================
- Coverage   99.21%   97.71%   -1.51%     
==========================================
  Files          42       50       +8     
  Lines        3182     3190       +8     
==========================================
- Hits         3157     3117      -40     
- Misses         17       55      +38     
- Partials        8       18      +10     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 97.69% <62.06%> (?)
-tags go_json 97.63% <62.06%> (?)
-tags nomsgpack 97.67% <62.06%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.25 97.71% <62.71%> (?)
go-1.26 97.71% <62.71%> (?)
macos-latest 97.71% <62.71%> (-1.51%) ⬇️
ubuntu-latest 97.71% <62.71%> (-1.51%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

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.

1 participant