Skip to content

Accept string bodies for octet-stream uploads#1213

Merged
RhysSullivan merged 1 commit into
mainfrom
fix/openapi-octet-stream-string-body
Jun 29, 2026
Merged

Accept string bodies for octet-stream uploads#1213
RhysSullivan merged 1 commit into
mainfrom
fix/openapi-octet-stream-string-body

Conversation

@RhysSullivan

Copy link
Copy Markdown
Owner

What

Octet-stream operations were rejecting a plain string body with application/octet-stream request body must be bytes; provide bodyBase64. This broke uploads that pass text content as a string, like the Microsoft Graph drive item content update (drivesUpdateItemsContent).

Why

The bodyBase64 work (#1137) added a strict guard that throws whenever an octet-stream body isn't already bytes. But applyRequestBody has always handled a string body for octet-stream (it sends it as-is), so the guard rejected a shape the request layer was happy to send. Callers passing string content started failing once that path shipped.

Fix

Only reject when the body is neither bytes nor a string. A string body goes through as UTF-8 bytes (the long-standing behavior); genuinely binary content still uses bodyBase64, and an object body is still rejected.

Updated the octet-stream test that asserted the old "string body fails" behavior to assert it now passes through as UTF-8 bytes. Full non-json-body suite passes (28 tests).

A plain string `body` was being rejected for octet-stream operations
with "request body must be bytes; provide bodyBase64", which broke
existing callers (such as the Microsoft Graph drive item content
upload) that send text content as a string. The request layer already
handles a string body, so let it through as UTF-8 bytes. Binary
uploads still use bodyBase64.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
executor-cloud 612f03e Jun 29 2026, 06:11 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
executor-marketing 612f03e Commit Preview URL

Branch Preview URL
Jun 29 2026, 06:10 PM

@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown

Greptile Summary

This patch restores the pre-bodyBase64 behavior for application/octet-stream uploads: a plain string body now flows through to the wire as UTF-8 bytes instead of being rejected by the strict guard introduced in #1137.

  • invoke.ts: The guard that throws "request body must be bytes; provide bodyBase64" is extended with a typeof bodyValue !== "string" short-circuit so strings are allowed through. applyRequestBody already handles string bodies for octet-stream via bodyText, so no downstream change is needed. Objects and other non-byte, non-string shapes still hit the error.
  • non-json-body.test.ts: The test that previously asserted a string body fails is inverted to assert it passes through verbatim as UTF-8 bytes, with the correct application/octet-stream content type on the wire.

Confidence Score: 5/5

Safe to merge — the change is a one-line relaxation of a validation guard that restores a previously working call path without touching any other body type or request flow.

The guard change is minimal and directly matches what applyRequestBody already accepted. The test now confirms end-to-end that a string body reaches the server as the correct UTF-8 bytes under application/octet-stream. Object bodies, nulls, and numbers are still caught by the guard. No other code paths are affected.

No files require special attention.

Important Files Changed

Filename Overview
packages/plugins/openapi/src/sdk/invoke.ts Relaxes the octet-stream body guard to allow plain string values through, matching the long-standing behavior of applyRequestBody. Only non-string, non-bytes values (e.g. objects) still trigger the error. Change is minimal and correct.
packages/plugins/openapi/src/sdk/non-json-body.test.ts Updated test asserts the new behavior: string body reaches the wire as UTF-8 bytes with the correct application/octet-stream content type. Uses a non-base64 string to make it clear the value is not decoded.
.changeset/octet-stream-string-body.md Patch changeset correctly describing the fix for @executor-js/plugin-openapi.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[invoke: bodyValue resolved] --> B{isOctetStream?}
    B -- No --> C[other content-type path]
    B -- Yes --> D{typeof bodyValue === 'string'?}
    D -- Yes --> E[✅ pass through to applyRequestBody]
    D -- No --> F{toUint8Array != null?}
    F -- Yes --> E
    F -- No --> G[❌ OpenApiInvocationError: provide bodyBase64]
    E --> H[applyRequestBody]
    H --> I{string?}
    I -- Yes --> J[bodyText — UTF-8 bytes on wire]
    I -- No --> K{bytes?}
    K -- Yes --> L[bodyUint8Array]
    K -- No --> M[JSON.stringify fallback — dead code under guard]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[invoke: bodyValue resolved] --> B{isOctetStream?}
    B -- No --> C[other content-type path]
    B -- Yes --> D{typeof bodyValue === 'string'?}
    D -- Yes --> E[✅ pass through to applyRequestBody]
    D -- No --> F{toUint8Array != null?}
    F -- Yes --> E
    F -- No --> G[❌ OpenApiInvocationError: provide bodyBase64]
    E --> H[applyRequestBody]
    H --> I{string?}
    I -- Yes --> J[bodyText — UTF-8 bytes on wire]
    I -- No --> K{bytes?}
    K -- Yes --> L[bodyUint8Array]
    K -- No --> M[JSON.stringify fallback — dead code under guard]
Loading

Reviews (1): Last reviewed commit: "fix(openapi): accept a string body for o..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Cloudflare preview

Torn down — the PR is closed.

@RhysSullivan RhysSullivan merged commit dc9bf71 into main Jun 29, 2026
14 of 15 checks passed
@RhysSullivan RhysSullivan mentioned this pull request Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant