Skip to content

feat(github): honor the raw media type on GET /repos/:owner/:repo/contents/:path - #208

Open
yonatangross wants to merge 1 commit into
vercel-labs:mainfrom
yonatangross:fix/github-contents-raw-media-type
Open

feat(github): honor the raw media type on GET /repos/:owner/:repo/contents/:path#208
yonatangross wants to merge 1 commit into
vercel-labs:mainfrom
yonatangross:fix/github-contents-raw-media-type

Conversation

@yonatangross

Copy link
Copy Markdown

Summary

  • GET /repos/:owner/:repo/contents/:path returns the file bytes with Content-Type: application/vnd.github.raw when the request accepts application/vnd.github.raw or application/vnd.github.raw+json, as GitHub does; the JSON envelope is unchanged for every other Accept
  • Symlinks resolve like the existing /:owner/:repo/raw/:ref/:path route

Why

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

File Change
routes/contents.ts raw media-type branch in getContents
__tests__/contents-commits.test.ts PUT a file, GET with .raw+json → bytes + application/vnd.github.raw; default Accept still returns encoding: base64

Test plan

  • pnpm --filter @emulators/github test (6 files pass)
  • pnpm -r build
  • pnpm --filter @emulators/github lint (0 errors, no new warnings)

…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.
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown
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)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix on Vercel

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