Include formdata on form multipart requests #26
Closed
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.
Motivation
In a project recently, I was troubleshooting some failed form submissions with
requestand it was very useful for me to see the actual body of the multipart/form-data request. When I asked on Stack Overflow how to get the raw message body of the HTTP request, a few people suggested that I use this project (request-debug).But until now, request-debug didn't actually show the body of multipart/form-data requests! So I added it.
Safety
This adds a dependency on
form-data. That doesn't seem unreasonable, becauserequestis already bringing in a version ofform-data. But it's bringing in a slightly older version without the very usefulgetBuffer()method, so this change just monkey-patches the useful code onto the old object. The ideal solution would be forrequestto update their dependency onform-datato bring in 2.5.0 or higher.This inspects a property (
_form) that is internal torequest. If that is ever removed, request-debug would fail safe. But if it was changed to a different object (not a form-data object) that could cause request-debug to fail.Basically, this should work just fine until the next major version of
form-datais released, and possibly longer.