Skip to content

Commit

Permalink
Consume request body in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jul 6, 2023
1 parent f3c1662 commit 38596af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion test/e2e/cancel-request/app/edge-route/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export const runtime = 'edge'
let streamable
let requestAborted = false

export function GET(req: Request): Response {
export async function GET(req: Request): Promise<Response> {
// Consume the entire request body.
// This is so we don't confuse the request close with the connection close.
await req.text()

// The 2nd request should render the stats. We don't use a query param
// because edge rendering will create a different bundle for that.
if (streamable) {
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/cancel-request/app/node-route/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const dynamic = 'force-dynamic'
let streamable
let requestAborted = false

export function GET(req: Request): Response {
export async function GET(req: Request): Promise<Response> {
// Consume the entire request body.
// This is so we don't confuse the request close with the connection close.
await req.text()

// The 2nd request should render the stats. We don't use a query param
// because edge rendering will create a different bundle for that.
if (streamable) {
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/cancel-request/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const config = {
let streamable
let requestAborted = false

export default function handler(req: Request): Response {
export default async function handler(req: Request): Promise<Response> {
// Consume the entire request body.
// This is so we don't confuse the request close with the connection close.
await req.text()

// The 2nd request should render the stats. We don't use a query param
// because edge rendering will create a different bundle for that.
if (streamable) {
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/cancel-request/pages/api/edge-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const config = {
let streamable
let requestAborted = false

export default function handler(req: Request): Response {
export default async function handler(req: Request): Promise<Response> {
// Consume the entire request body.
// This is so we don't confuse the request close with the connection close.
await req.text()

// The 2nd request should render the stats. We don't use a query param
// because edge rendering will create a different bundle for that.
if (streamable) {
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/cancel-request/pages/api/node-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export default function handler(
_req: IncomingMessage,
res: ServerResponse
): void {
// Pages API requests have already consumed the body.
// This is so we don't confuse the request close with the connection close.

// The 2nd request should render the stats. We don't use a query param
// because edge rendering will create a different bundle for that.
if (readable) {
Expand Down

0 comments on commit 38596af

Please sign in to comment.