fix: Pages API body parser for invalid JSON and repeated form keys#446
fix: Pages API body parser for invalid JSON and repeated form keys#446JaredStowell wants to merge 3 commits intocloudflare:mainfrom
Conversation
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d8ceba9cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| middlewareRewriteStatus ?? response.status, | ||
| responseHeaders, | ||
| compress, | ||
| response.statusText || undefined, |
There was a problem hiding this comment.
Drop stale status text when rewrite overrides status
When middlewareRewriteStatus overrides the downstream response status, this call still forwards response.statusText, so the reason phrase can describe a different status code than the one actually sent (for example, a middleware rewrite to 403 combined with an API response that set statusText to Invalid JSON yields 403 Invalid JSON). This mismatch was introduced by propagating statusText and affects any rewritten API/page response with a custom status text; only preserve response.statusText when the final status code is unchanged.
Useful? React with 👍 / 👎.
Bring Pages API body parsing in line with Next.js for JSON and urlencoded requests.
Changes
400 Invalid JSONfor malformedapplication/jsonrequests instead of passing raw strings to handlersapplication/x-www-form-urlencodedkeys as arrays viaquerystring.decode(){}to match Next.js behaviorapplication/ld+jsonas JSONstatusTextthrough the Pages production server pathTesting
pnpm test tests/api-handler.test.ts tests/pages-router.test.ts tests/entry-templates.test.ts -upnpm test tests/features.test.ts -t "production server compression"pnpm run fmtpnpm run typecheck