fix(executor): short-circuit 204 No Content before binary response routing - #906
fix(executor): short-circuit 204 No Content before binary response routing#906TheSecMaven wants to merge 1 commit into
Conversation
…uting A 204 No Content response that still carries a non-empty Content-Type header (text/html on calendar.events.delete and drive.files.delete) was being routed to the binary-file handler purely on that header, which wrote a stray zero-byte download.html into the caller's cwd and printed a spurious success status for commands with no --output flag and nothing to do with downloading. Introduce classify_response_body(status, content_type) so a 204 is always treated as having no body to read or write, independent of whatever Content-Type the endpoint happens to attach to it.
🦋 Changeset detectedLatest commit: 3ed0337 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This PR has been inactive for 72 hours. Closing to keep the queue clean. |
|
This PR was closed because it has been stalled for 72 hours. Feel free to magically reopen it if you want to continue working on it! |
Problem
calendar.events.deleteanddrive.files.deleteboth return an HTTP 204 No Contentresponse, but the response still carries a non-empty
Content-Typeheader(
text/html). The executor's JSON-vs-binary routing decision was made purely fromthat header, with no earlier check on status code, so a 204 with a
text/htmlContent-Type fell through into the binary-file handler.
Result: running a plain delete with no
--outputflag at all —— silently creates a zero-byte
download.htmlin the caller's current workingdirectory, and prints a
"status": "success", "saved_file": "download.html"JSONblob that has nothing to do with what the command actually did.
Related: #743, and the same root cause as the earlier #749 (auto-closed by the stale
bot before review — this PR reimplements the same fix with test coverage).
Fix
Added
classify_response_body(status, content_type) -> ResponseBodyKindand made itthe single source of truth for how a response body gets handled. A
204 NO_CONTENTis now always classified as
NoContentregardless ofContent-Type, so nothing isread from or written for it — matching the behavior of every other delete-style
endpoint that returns a genuinely empty body.
Tests
Six new unit tests on
classify_response_bodycover the exact failure combination(204 +
text/html), 204 with an empty or evenapplication/jsonContent-Type, andthe unaffected 200-JSON / 200-binary cases. Full crate suite:
cargo test -p google-workspace-cli— 707 passed, 0 failed.cargo clippy --all-targetsshows nonew warnings from this change.
On the S3 idea
Unrelated to this bug — see the sibling PR for the large-binary-download issue,
where that question actually applies.