Fix multipart form encoding for PUT requests#245
Open
ndbroadbent wants to merge 2 commits into
Open
Conversation
- Add rackup gem dependency for Ruby 3.0+ - Update localhost_server.rb to use Rackup::Handler instead of Rack::Handler - Fixes test suite that was broken due to rack/webrick handler being moved to separate rackup gem 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
PUT requests now properly handle multipart form data with files, matching POST behavior: - Check form.multipart? to detect multipart forms in Putable module - Use httppost for multipart forms instead of always using upload/read_callback - Set customrequest='PUT' to override libcurl's default POST method when using httppost - Add comprehensive tests for multipart PUT requests Fixes long-standing issue where PUT requests would not form-encode multipart data, causing Content-Type header to be missing and files to be sent incorrectly. Resolves typhoeus/typhoeus#389 and OpenAPITools/openapi-generator#3138 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Aug 10, 2025
voxik
reviewed
Aug 10, 2025
|
|
||
| if Gem.ruby_version >= Gem::Version.new("3.0.0") | ||
| gem "webrick" | ||
| gem "rackup" |
Contributor
There was a problem hiding this comment.
I don't think there is any reason to include rackup based on Ruby version. Rackup is needed when Rack 3+ is used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a long-standing issue where PUT requests could not properly handle multipart form data with files. PUT requests now correctly set
Content-Type: multipart/form-dataheaders and encode form data identically to POST requests.Problem
PUT requests with multipart form data (containing files) were not being form-encoded correctly:
Content-Type: multipart/form-dataheader was setSolution
Updated the
Putablemodule to mirrorPostablebehavior:form.multipart?detectionhttppostfor multipart forms instead of always usingupload/read_callbackcustomrequest = 'PUT'to override libcurl's default POST behavior when usinghttppostChanges
lib/ethon/easy/http/putable.rb: Updatedset_formmethod to handle multipart formsspec/ethon/easy/http/put_spec.rb: Added comprehensive tests for multipart PUT requestsGemfile+spec/support/localhost_server.rb: Fixed test suite compatibility with modern Rack versionsTesting
All existing tests pass, plus new tests verify:
httppostinstead ofuploadmultipart/form-datacontent type is sent correctlyRelated Issues
Closes:
Related to:
This resolves a 10+ year old issue that affected Ruby HTTP clients generated by OpenAPI Generator and direct Typhoeus/Ethon usage.