[PR #428] [MERGED] fix: align Pages API body parsing and res.send(Buffer) #568

Closed
opened 2026-05-06 13:08:48 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/428
Author: @JaredStowell
Created: 3/10/2026
Status: Merged
Merged: 3/11/2026
Merged by: @james-elicx

Base: mainHead: jstowell/fix-pages-api-body-parity


📝 Commits (5)

  • 1ca97c9 Fix Buffer handling in Pages API res
  • 09d6224 fix: skip reporting handled Pages API parse errors
  • 37eb489 Merge remote-tracking branch 'origin/main' into jstowell/fix-pages-api-body-parity
  • b41e76e address review: blank line nit, content-length parity for Buffer, fix duplicate Content-Length in sendCompressed
  • f3f03f7 fix: set content-length for Buffer in production res.send() to match dev parity

📊 Changes

8 files changed (+266 additions, -68 deletions)

View changed files

📝 packages/vinext/src/entries/pages-server-entry.ts (+38 -17)
📝 packages/vinext/src/server/api-handler.ts (+28 -7)
📝 packages/vinext/src/server/prod-server.ts (+4 -1)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+54 -29)
📝 tests/api-handler.test.ts (+58 -14)
tests/fixtures/pages-basic/pages/api/echo-body.ts (+5 -0)
tests/fixtures/pages-basic/pages/api/send-buffer.ts (+5 -0)
📝 tests/pages-router.test.ts (+74 -0)

📄 Description

Summary

Fix three Pages Router API compatibility gaps to match Next.js behavior more closely:

  • res.send(Buffer) now sends raw bytes with application/octet-stream instead of JSON-stringifying Buffer metadata
  • application/x-www-form-urlencoded body parsing now preserves repeated keys as arrays
  • malformed JSON bodies now return 400 Invalid JSON instead of falling through as a raw string

This updates both Pages API paths so dev and production stay in sync:

  • packages/vinext/src/server/api-handler.ts
  • packages/vinext/src/entries/pages-server-entry.ts

Tests

Added coverage for all three cases in:

  • tests/api-handler.test.ts
  • tests/pages-router.test.ts

Added Pages Router fixture routes for integration coverage:

  • tests/fixtures/pages-basic/pages/api/echo-body.ts
  • tests/fixtures/pages-basic/pages/api/send-buffer.ts

Updated:

  • tests/__snapshots__/entry-templates.test.ts.snap

Verification

Ran:

  • pnpm test tests/api-handler.test.ts
  • pnpm test tests/pages-router.test.ts
  • pnpm test tests/entry-templates.test.ts -u
  • pnpm run fmt
  • pnpm run typecheck
  • pnpm test

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/428 **Author:** [@JaredStowell](https://github.com/JaredStowell) **Created:** 3/10/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `jstowell/fix-pages-api-body-parity` --- ### 📝 Commits (5) - [`1ca97c9`](https://github.com/cloudflare/vinext/commit/1ca97c9203c8cab15444919f37090c07e71724a6) Fix Buffer handling in Pages API res - [`09d6224`](https://github.com/cloudflare/vinext/commit/09d6224ae0c54e755c25094e7ff269fde1392a2e) fix: skip reporting handled Pages API parse errors - [`37eb489`](https://github.com/cloudflare/vinext/commit/37eb48948e894a227a1c10361c12b490ea925fd0) Merge remote-tracking branch 'origin/main' into jstowell/fix-pages-api-body-parity - [`b41e76e`](https://github.com/cloudflare/vinext/commit/b41e76e20448b7abf69802ec30fe2d672d03d593) address review: blank line nit, content-length parity for Buffer, fix duplicate Content-Length in sendCompressed - [`f3f03f7`](https://github.com/cloudflare/vinext/commit/f3f03f74d9d654a52b4db9cac8e1065b3cdae329) fix: set content-length for Buffer in production res.send() to match dev parity ### 📊 Changes **8 files changed** (+266 additions, -68 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+38 -17) 📝 `packages/vinext/src/server/api-handler.ts` (+28 -7) 📝 `packages/vinext/src/server/prod-server.ts` (+4 -1) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+54 -29) 📝 `tests/api-handler.test.ts` (+58 -14) ➕ `tests/fixtures/pages-basic/pages/api/echo-body.ts` (+5 -0) ➕ `tests/fixtures/pages-basic/pages/api/send-buffer.ts` (+5 -0) 📝 `tests/pages-router.test.ts` (+74 -0) </details> ### 📄 Description ## Summary Fix three Pages Router API compatibility gaps to match Next.js behavior more closely: - `res.send(Buffer)` now sends raw bytes with `application/octet-stream` instead of JSON-stringifying Buffer metadata - `application/x-www-form-urlencoded` body parsing now preserves repeated keys as arrays - malformed JSON bodies now return `400 Invalid JSON` instead of falling through as a raw string This updates both Pages API paths so dev and production stay in sync: - `packages/vinext/src/server/api-handler.ts` - `packages/vinext/src/entries/pages-server-entry.ts` ## Tests Added coverage for all three cases in: - `tests/api-handler.test.ts` - `tests/pages-router.test.ts` Added Pages Router fixture routes for integration coverage: - `tests/fixtures/pages-basic/pages/api/echo-body.ts` - `tests/fixtures/pages-basic/pages/api/send-buffer.ts` Updated: - `tests/__snapshots__/entry-templates.test.ts.snap` ## Verification Ran: - `pnpm test tests/api-handler.test.ts` - `pnpm test tests/pages-router.test.ts` - `pnpm test tests/entry-templates.test.ts -u` - `pnpm run fmt` - `pnpm run typecheck` - `pnpm test` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:48 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#568
No description provided.