feat(github): honor the raw media type on GET /repos/:owner/:repo/contents/:path - #208
Open
yonatangross wants to merge 1 commit into
Open
Conversation
…tents/:path GitHub returns the file bytes (Content-Type application/vnd.github.raw) when the request accepts application/vnd.github.raw or .raw+json; the emulator always returned the JSON envelope, so clients that read files this way (e.g. a service's get_file_content) got JSON where they expected text. Symlinks resolve like the /raw/ route.
Contributor
|
@yonatangross is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Comment on lines
+463
to
+466
| // Raw media type (`application/vnd.github.raw` / `.raw+json`): return the | ||
| // file bytes, as GitHub does, instead of the JSON envelope. | ||
| const accept = c.req.header("Accept") ?? ""; | ||
| if (/application\/vnd\.github\.raw(\+json)?/i.test(accept)) { |
Contributor
There was a problem hiding this comment.
Suggested change
| // Raw media type (`application/vnd.github.raw` / `.raw+json`): return the | |
| // file bytes, as GitHub does, instead of the JSON envelope. | |
| const accept = c.req.header("Accept") ?? ""; | |
| if (/application\/vnd\.github\.raw(\+json)?/i.test(accept)) { | |
| // Raw media type (`application/vnd.github.raw` / `.raw+json` / the | |
| // versioned `.v3.raw` sent by Octokit's `mediaType: { format: "raw" }`): | |
| // return the file bytes, as GitHub does, instead of the JSON envelope. | |
| const accept = c.req.header("Accept") ?? ""; | |
| if (/application\/vnd\.github(?:\.v3)?\.raw(\+json)?/i.test(accept)) { |
Raw content Accept-header regex misses the versioned application/vnd.github.v3.raw media type sent by default Octokit clients, so they receive the JSON envelope instead of raw bytes.
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.
Summary
GET /repos/:owner/:repo/contents/:pathreturns the file bytes withContent-Type: application/vnd.github.rawwhen the request acceptsapplication/vnd.github.raworapplication/vnd.github.raw+json, as GitHub does; the JSON envelope is unchanged for every otherAccept/:owner/:repo/raw/:ref/:pathrouteWhy
Clients that read files this way (a
get_file_content()sending the raw media type, the documented GitHub pattern) got the base64 JSON envelope from the emulator where production returns text. Found by Yonatan-HQ/platform's emulate tier driving its real GitHub service against 0.10.0's stateful contents API.Changes
routes/contents.tsgetContents__tests__/contents-commits.test.ts.raw+json→ bytes +application/vnd.github.raw; default Accept still returnsencoding: base64Test plan
pnpm --filter @emulators/github test(6 files pass)pnpm -r buildpnpm --filter @emulators/github lint(0 errors, no new warnings)