fix(executor): short-circuit 204 No Content before binary response routing - #906
Open
TheSecMaven wants to merge 1 commit into
Open
fix(executor): short-circuit 204 No Content before binary response routing#906TheSecMaven wants to merge 1 commit into
TheSecMaven 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 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.
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.