fix: preserve binary response bodies in curl and HTTP bridge#178
Open
mutewinter wants to merge 1 commit intovercel-labs:mainfrom
Open
fix: preserve binary response bodies in curl and HTTP bridge#178mutewinter wants to merge 1 commit intovercel-labs:mainfrom
mutewinter wants to merge 1 commit intovercel-labs:mainfrom
Conversation
|
@mutewinter is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Thanks. Could you address the one comment? |
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.
I wrote this:
I ran into this issue when I noticed some corrupted JPEGs downloaded by an agent using curl, tracked it down to this, it fixes a little larger than I expected, but it does seem like it works fine for me.
Agent wrote this:
FetchResult.bodywas typed asstringand decoded viaTextDecoder/response.text(), corrupting any binary response (JPEG, PNG, etc.) — bytes0xFFbecameEF BF BD(UTF-8 replacement character) on disk.Root cause:
responseToResultinsrc/network/fetch.tsalways decoded the response as UTF-8 text regardless of content type.Changes:
FetchResult.bodyis nowUint8Array— raw bytes, never text-decodedresponseToResultreads via streaminggetReader()orarrayBuffer()instead ofTextDecoder/response.text()curlwritesUint8Arraydirectly to the filesystem and renders stdout viafromBuffer(body, "binary")(latin1, one char per byte)bridge-handler→sync-backend) serialises the body asbodyBase64over JSON so it survivesJSON.stringifyacross the SharedArrayBuffer boundary; workers decode withatobjb_httpin the Python bridge readsbodyBase64, decodes tobytes(content) and UTF-8 text (text) — matching therequests.ResponsecontractBreaking change for custom
fetchoption users:SecureFetchimplementations must now returnbody: Uint8Arrayinstead ofbody: string.