Skip to content

fix: simplify isBinaryPayload to use encode="bytes" as binary signal#3958

Open
Copilot wants to merge 7 commits into
mainfrom
copilot/revert-pr-3918-changes
Open

fix: simplify isBinaryPayload to use encode="bytes" as binary signal#3958
Copilot wants to merge 7 commits into
mainfrom
copilot/revert-pr-3918-changes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

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.

kazrael2119 and others added 3 commits May 12, 2026 08:28
(cherry picked from commit c2f06b1)

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 @encode("bytes") handling from PR #3918 May 12, 2026
Copilot AI requested a review from kazrael2119 May 12, 2026 08:40
@kazrael2119 kazrael2119 changed the title Isolate binary payload @encode("bytes") handling from PR #3918 fix: simplify isBinaryPayload to use encode="bytes" as binary signal May 12, 2026
@qiaozha qiaozha added p0 priority 0 HRLC labels May 13, 2026
@JialinHuang803 JialinHuang803 marked this pull request as ready for review May 15, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

HRLC p0 priority 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[typespec-ts] */* content type should be treated as binary when body is bytes

4 participants