CLI-1779: Restrict empty-body JSON fallback to POST only#2024
CLI-1779: Restrict empty-body JSON fallback to POST only#2024deepakmishra2 wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2024 +/- ##
=========================================
Coverage 92.49% 92.49%
- Complexity 1992 1994 +2
=========================================
Files 123 123
Lines 7234 7236 +2
=========================================
+ Hits 6691 6693 +2
Misses 543 543 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Try the dev build for this PR: https://acquia-cli.s3.amazonaws.com/build/pr/2024/acli.phar |
There was a problem hiding this comment.
Pull request overview
This PR updates ApiBaseCommand::execute() so the “empty JSON body fallback” ({} via Guzzle’s json option) is only applied to POST requests with no request body parameters, avoiding PHP cURL seek warnings for bodyless PUT requests generated from the OpenAPI spec.
Changes:
- Restricts the empty-body JSON fallback to
POSTrequests only inApiBaseCommand. - Adds PHPUnit coverage to ensure:
- bodyless POST sends
{}(keeps prior behavior where required), - POST with a real body does not send the fallback,
- bodyless PUT does not send
{}(regression coverage for CLI-1779).
- bodyless POST sends
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Command/Api/ApiBaseCommand.php | Limits the empty {} JSON fallback to POST-only to prevent non-seekable stream issues on bodyless PUT. |
| tests/phpunit/src/Commands/Api/ApiCommandTest.php | Adds tests covering POST fallback behavior and the PUT regression scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PUT/PATCH endpoints with no requestBody properties (e.g.
site-instances:domain:add) must not receive `{}`: Guzzle creates a
non-seekable stream for the empty stdClass which causes
`curl_setopt_array(): Stream does not support seeking` on PHP 8.x.
The empty-body guard (needed so body-less POST requests get a
Content-Type header) is now conditional on the HTTP method being POST.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
ApiBaseCommand::executepreviously sent{}as a JSON body for any POST/PUT/PATCH with no post paramsPUT /site-instances/{siteId}.{environmentId}/domains/{domainName}(api:site-instances:domain:add), this triggeredcurl_setopt_array(): Stream does not support seeking— PHP curl cannot seek on the non-seekable stream Guzzle creates for the emptystdClassTest plan
testBodylessPostSendsEmptyJsonBody— POST with no body still sends{}testPostWithBodyDoesNotSendEmptyFallback— POST with body does not get the empty fallbacktestBodylessPutDoesNotSendEmptyJsonBody— PUT with no body does NOT send{}(regression test for CLI-1779)acli api:site-instances:domain:addagainst a real environment to confirm the PHP warning is gone🤖 Generated with Claude Code