Skip to content

Commit d7691ea

Browse files
committed
Added test cases for NextResponse and Response
1 parent 050da9f commit d7691ea

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export async function POST(req: Request) {
2+
const body = await req.json(); // $ MISSING: Source
3+
4+
new Response(body, {headers: { 'Content-Type': 'application/json' }}); // This is okay, since content type is set to application/json
5+
new Response(body, {headers: { 'Content-Type': 'text/html' }}); // $ MISSING: Alert
6+
7+
const headers2 = new Headers(req.headers);
8+
headers2.append('Content-Type', 'application/json');
9+
new Response(body, { headers: headers2 }); // This is okay, since content type is set to application/json
10+
11+
const headers3 = new Headers(req.headers);
12+
headers3.append('Content-Type', 'text/html');
13+
new Response(body, { headers: headers3 }); // $ MISSING: Alert
14+
15+
const headers4 = new Headers({
16+
...Object.fromEntries(req.headers),
17+
'Content-Type': 'application/json'
18+
});
19+
new Response(body, { headers: headers4 }); // This is okay, since content type is set to application/json
20+
21+
const headers5 = new Headers({
22+
...Object.fromEntries(req.headers),
23+
'Content-Type': 'text/html'
24+
});
25+
new Response(body, { headers: headers5 }); // $ MISSING: Alert
26+
27+
const headers = new Headers(req.headers);
28+
headers.set('Content-Type', 'text/html');
29+
return new Response(body, { headers }); // $ MISSING: Alert
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
3+
export async function POST(req: NextRequest) {
4+
const data = await req.json(); // $ MISSING: Source
5+
new NextResponse(data, {headers: { 'Content-Type': 'text/html' }}); // $ MISSING: Alert
6+
return new NextResponse(data, { headers: req.headers }); // $ MISSING: Alert
7+
}

0 commit comments

Comments
 (0)