Skip to content

CLI-1779: Restrict empty-body JSON fallback to POST only#2024

Open
deepakmishra2 wants to merge 4 commits into
mainfrom
CLI-1779
Open

CLI-1779: Restrict empty-body JSON fallback to POST only#2024
deepakmishra2 wants to merge 4 commits into
mainfrom
CLI-1779

Conversation

@deepakmishra2

Copy link
Copy Markdown
Contributor

Summary

  • ApiBaseCommand::execute previously sent {} as a JSON body for any POST/PUT/PATCH with no post params
  • For PUT /site-instances/{siteId}.{environmentId}/domains/{domainName} (api:site-instances:domain:add), this triggered curl_setopt_array(): Stream does not support seeking — PHP curl cannot seek on the non-seekable stream Guzzle creates for the empty stdClass
  • Fix restricts the empty-body guard to POST only; PUT/PATCH endpoints without a body schema send no body at all

Test plan

  • testBodylessPostSendsEmptyJsonBody — POST with no body still sends {}
  • testPostWithBodyDoesNotSendEmptyFallback — POST with body does not get the empty fallback
  • testBodylessPutDoesNotSendEmptyJsonBody — PUT with no body does NOT send {} (regression test for CLI-1779)
  • Run acli api:site-instances:domain:add against a real environment to confirm the PHP warning is gone

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 20, 2026 05:39
@deepakmishra2 deepakmishra2 self-assigned this Jul 20, 2026
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.49%. Comparing base (582c1fb) to head (c7dc3f8).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@deepakmishra2 deepakmishra2 changed the title fix(CLI-1779): restrict empty-body JSON fallback to POST only CLI-1779: Restrict empty-body JSON fallback to POST only Jul 20, 2026
@deepakmishra2 deepakmishra2 added the bug Something isn't working label Jul 20, 2026
@github-actions

Copy link
Copy Markdown

Try the dev build for this PR: https://acquia-cli.s3.amazonaws.com/build/pr/2024/acli.phar

curl -OL https://acquia-cli.s3.amazonaws.com/build/pr/2024/acli.phar
chmod +x acli.phar

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 POST requests only in ApiBaseCommand.
  • 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).

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.

Comment thread tests/phpunit/src/Commands/Api/ApiCommandTest.php
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants