Skip to content

Commit 38596af

Browse files
committed
Consume request body in tests
1 parent f3c1662 commit 38596af

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

test/e2e/cancel-request/app/edge-route/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ export const runtime = 'edge'
55
let streamable
66
let requestAborted = false
77

8-
export function GET(req: Request): Response {
8+
export async function GET(req: Request): Promise<Response> {
9+
// Consume the entire request body.
10+
// This is so we don't confuse the request close with the connection close.
11+
await req.text()
12+
913
// The 2nd request should render the stats. We don't use a query param
1014
// because edge rendering will create a different bundle for that.
1115
if (streamable) {

test/e2e/cancel-request/app/node-route/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export const dynamic = 'force-dynamic'
77
let streamable
88
let requestAborted = false
99

10-
export function GET(req: Request): Response {
10+
export async function GET(req: Request): Promise<Response> {
11+
// Consume the entire request body.
12+
// This is so we don't confuse the request close with the connection close.
13+
await req.text()
14+
1115
// The 2nd request should render the stats. We don't use a query param
1216
// because edge rendering will create a different bundle for that.
1317
if (streamable) {

test/e2e/cancel-request/middleware.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export const config = {
77
let streamable
88
let requestAborted = false
99

10-
export default function handler(req: Request): Response {
10+
export default async function handler(req: Request): Promise<Response> {
11+
// Consume the entire request body.
12+
// This is so we don't confuse the request close with the connection close.
13+
await req.text()
14+
1115
// The 2nd request should render the stats. We don't use a query param
1216
// because edge rendering will create a different bundle for that.
1317
if (streamable) {

test/e2e/cancel-request/pages/api/edge-api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export const config = {
77
let streamable
88
let requestAborted = false
99

10-
export default function handler(req: Request): Response {
10+
export default async function handler(req: Request): Promise<Response> {
11+
// Consume the entire request body.
12+
// This is so we don't confuse the request close with the connection close.
13+
await req.text()
14+
1115
// The 2nd request should render the stats. We don't use a query param
1216
// because edge rendering will create a different bundle for that.
1317
if (streamable) {

test/e2e/cancel-request/pages/api/node-api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default function handler(
1313
_req: IncomingMessage,
1414
res: ServerResponse
1515
): void {
16+
// Pages API requests have already consumed the body.
17+
// This is so we don't confuse the request close with the connection close.
18+
1619
// The 2nd request should render the stats. We don't use a query param
1720
// because edge rendering will create a different bundle for that.
1821
if (readable) {

0 commit comments

Comments
 (0)