fix: forward multipart/form-data fields when a request has no files - #185
Merged
Conversation
PassageService::callService() only entered the multipart-aware branch when allFiles() was non-empty, so a plain multipart/form-data request with only text fields fell through to the raw passthrough branch, which reads getContent(). PHP consumes php://input while populating $_POST/$_FILES for multipart requests before userland code runs, so getContent() is always empty for them, and the upstream call was dispatched with no body and none of the submitted fields. Detect multipart/form-data by Content-Type as well as by the presence of files, so text-only multipart requests are still forwarded via $request->post() instead of silently dropping the payload.
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.
What was broken
PassageService::callService()only entered the multipart-aware branch when$request->allFiles()was non-empty. Amultipart/form-datarequest with only text fields (no file fields) — a completely standard form submission — matched none of the earlier branches and fell into the raw-passthrough fallback, which builds the outbound body from$request->getContent().PHP consumes
php://inputwhile populating$_POST/$_FILESduring request initialization for multipart requests, before any userland code runs, sogetContent()is always empty for them. The fallback branch's$body !== ''check was therefore always false, and the upstream call was dispatched with no body and none of the submitted fields — silently, with no error or exception.What changed
src/Services/PassageService.php: widened the multipart-handling condition to also trigger when theContent-Typeheader containsmultipart/form-data(checked case-insensitively, matching the convention already used inHasHmacAuth), not just when files are present. Text-only multipart requests are now forwarded via$request->post(), the same as the existing file-upload path.tests/Unit/PassageServiceTest.php: added regression tests covering a multipart/form-data POST with only text fields (asserting the fields reach the outbound request), and one covering case-insensitive Content-Type detection.Testing
vendor/bin/pint --dirty— passedcomposer test— full suite passes (156 tests, 422 assertions)Fixes #116