Skip to content

feat(client): prefer multipart and support url-encoded file uploads#428

Merged
fredbi merged 1 commit intogo-openapi:masterfrom
fredbi:feat/286-x-www-form-file
May 4, 2026
Merged

feat(client): prefer multipart and support url-encoded file uploads#428
fredbi merged 1 commit intogo-openapi:masterfrom
fredbi:feat/286-x-www-form-file

Conversation

@fredbi
Copy link
Copy Markdown
Member

@fredbi fredbi commented May 4, 2026

When an operation advertises both multipart/form-data and application/x-www-form-urlencoded in consumes, the runtime now prefers multipart regardless of the order produced by codegen. This avoids silently falling into the URL-encoded path (which doesn't stream and drops per-file Content-Type) just because it happened to be listed first.

When the caller does explicitly select application/x-www-form-urlencoded (e.g. via go-swagger's WithContentType option from go-swagger/go-swagger#3042), file fields are now properly URL-encoded as form values instead of producing a multipart body advertised under a urlencoded Content-Type. Removed the unreachable / non-conformant branch in mangleContentType that emitted "application/x-www-form-urlencoded; boundary=...".

Fixes #286

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.67%. Comparing base (1114423) to head (5436226).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
client/request.go 73.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #428      +/-   ##
==========================================
- Coverage   81.71%   81.67%   -0.05%     
==========================================
  Files          50       50              
  Lines        3397     3411      +14     
==========================================
+ Hits         2776     2786      +10     
- Misses        508      510       +2     
- Partials      113      115       +2     

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

When an operation advertises both multipart/form-data and
application/x-www-form-urlencoded in `consumes`, the runtime now prefers
multipart regardless of the order produced by codegen. This avoids silently
falling into the URL-encoded path (which doesn't stream and drops per-file
Content-Type) just because it happened to be listed first.

When the caller does explicitly select application/x-www-form-urlencoded
(e.g. via go-swagger's `WithContentType` option from go-swagger/go-swagger#3042),
file fields are now properly URL-encoded as form values instead of producing a
multipart body advertised under a urlencoded Content-Type. Removed the
unreachable / non-conformant branch in mangleContentType that emitted
"application/x-www-form-urlencoded; boundary=...".

Fixes go-openapi#286

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
@fredbi fredbi force-pushed the feat/286-x-www-form-file branch from 4c97827 to 5436226 Compare May 4, 2026 21:00
@fredbi fredbi merged commit d7fb83c into go-openapi:master May 4, 2026
21 checks passed
@fredbi fredbi deleted the feat/286-x-www-form-file branch May 4, 2026 21:04
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.

Support file upload with application/x-www-form-urlencoded

1 participant