fix: simplify isBinaryPayload to use encode="bytes" as binary signal#3958
Open
Copilot wants to merge 7 commits into
Open
fix: simplify isBinaryPayload to use encode="bytes" as binary signal#3958Copilot wants to merge 7 commits into
Copilot wants to merge 7 commits into
Conversation
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/c5b9a83f-2fec-4bc7-b44b-2393f9d65a94 Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/c5b9a83f-2fec-4bc7-b44b-2393f9d65a94 Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Revert changes from PR #3918
Isolate binary payload May 12, 2026
@encode("bytes") handling from PR #3918
@encode("bytes") handling from PR #3918
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.
fixes #3913
In TCGC, the encoding for a bytes response body is determined as follows:
For
*/*and application/octet-stream content types, TCGC natively sets the encode to "bytes".For all other content types (e.g., application/json, application/xml), a bytes response body defaults to "base64" encoding — unless the user explicitly annotates the body with @encode("bytes"), which overrides the encode to "bytes".
Given this behavior, the isBinaryPayload logic can be simplified: if encode === "bytes" and the content-type is not text/plain, return true directly; otherwise, fall through to the original logic. This approach:
Naturally handles the
*/*case — since TCGC already sets encode to "bytes" for wildcard and octet-stream content types, no special-casing for*/*is needed anymore.Correctly handles explicit @encode("bytes") annotations on non-binary content types (e.g., application/json + @encode("bytes") → treated as binary).
Preserves the text/plain exception — even with @encode("bytes"), text/plain should not be treated as a binary stream.
Keeps backward compatibility with m4 → TCGC migration, since the encode field reliably reflects the wire-level intent.
The dedicated
*/*wildcard detection code path can therefore be removed in favor of this unified encode-based check.