Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a09167cb
Commit
a09167cb
authored
Jan 12, 2026
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update test
parent
5ee6ebb0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
34 deletions
+4
-34
route.js
...ware-non-ascii-headers/app/app/api/route-headers/route.js
+2
-10
middleware-non-ascii-headers.test.ts
...re-non-ascii-headers/middleware-non-ascii-headers.test.ts
+2
-24
No files found.
test/e2e/middleware-non-ascii-headers/app/app/api/route-headers/route.js
View file @
a09167cb
/**
/**
* App Route handler that:
* App Route handler that reads request headers (tests NextRequest header conversion)
* 1. Reads request headers (tests NextRequest header conversion)
* 2. Sets response headers with non-ASCII values (tests outgoing header handling)
*/
*/
export
async
function
GET
(
request
)
{
export
async
function
GET
(
request
)
{
// Read incoming request headers
// Read incoming request headers
...
@@ -12,15 +10,9 @@ export async function GET(request) {
...
@@ -12,15 +10,9 @@ export async function GET(request) {
}
}
}
}
// Create response with non-ASCII header values
return
new
Response
(
JSON
.
stringify
(
requestHeaders
),
{
const
response
=
new
Response
(
JSON
.
stringify
(
requestHeaders
),
{
headers
:
{
headers
:
{
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
// Set non-ASCII response headers to verify they work
'x-response-city'
:
'Montréal'
,
'x-response-country'
:
'Österreich'
,
},
},
})
})
return
response
}
}
test/e2e/middleware-non-ascii-headers/middleware-non-ascii-headers.test.ts
View file @
a09167cb
...
@@ -269,15 +269,13 @@ describe('Middleware Non-ASCII Headers', () => {
...
@@ -269,15 +269,13 @@ describe('Middleware Non-ASCII Headers', () => {
// ============================================================
// ============================================================
// App Route Handler Tests
// App Route Handler Tests
// T
hese test fromNodeOutgoingHttpHeaders in NextRequest adapter
// T
est that App Route handlers can read headers correctly
// ============================================================
// ============================================================
describe
(
'App Route Handler'
,
()
=>
{
describe
(
'App Route Handler'
,
()
=>
{
// App Route handlers should see properly decoded headers (same as middleware)
// fromNodeOutgoingHttpHeaders applies mojibake recovery without encoding
it
(
'should read non-ASCII request headers correctly in route handler'
,
async
()
=>
{
it
(
'should read non-ASCII request headers correctly in route handler'
,
async
()
=>
{
// Test that App Route handlers can read mojibake headers correctly
// Test that App Route handlers can read mojibake headers correctly
//
fromNodeOutgoingHttpHeaders decodes mojibake but doesn't encode by default
//
The middleware encodes non-ASCII, server decodes them before route handler
const
res
=
await
fetchViaHTTP
(
const
res
=
await
fetchViaHTTP
(
next
.
url
,
next
.
url
,
'/api/route-headers'
,
'/api/route-headers'
,
...
@@ -297,26 +295,7 @@ describe('Middleware Non-ASCII Headers', () => {
...
@@ -297,26 +295,7 @@ describe('Middleware Non-ASCII Headers', () => {
expect
(
body
[
'x-country'
]).
toBe
(
'Österreich'
)
expect
(
body
[
'x-country'
]).
toBe
(
'Österreich'
)
})
})
// Response headers with non-ASCII values arrive as mojibake
// (UTF-8 bytes interpreted as Latin-1 by HTTP transport)
it
(
'should show that response headers with non-ASCII arrive as mojibake'
,
async
()
=>
{
// Test that route handlers setting non-ASCII response headers
// have those headers arrive as mojibake to the client
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/route-headers'
,
{},
{})
expect
(
res
.
status
).
toBe
(
200
)
// Response headers with non-ASCII values get mangled during HTTP transport
// UTF-8 bytes are interpreted as Latin-1 (mojibake)
const
cityHeader
=
res
.
headers
.
get
(
'x-response-city'
)
const
countryHeader
=
res
.
headers
.
get
(
'x-response-country'
)
// These arrive as mojibake: "Montréal" → "Montréal", "Österreich" → "Ãsterreich"
expect
(
cityHeader
).
toBe
(
toMojibake
(
'Montréal'
))
expect
(
countryHeader
).
toBe
(
toMojibake
(
'Österreich'
))
})
it
(
'should preserve intentional percent-encoding in route handler'
,
async
()
=>
{
it
(
'should preserve intentional percent-encoding in route handler'
,
async
()
=>
{
// Test that intentional percent-encoding is not double-encoded or decoded
const
res
=
await
fetchViaHTTP
(
const
res
=
await
fetchViaHTTP
(
next
.
url
,
next
.
url
,
'/api/route-headers'
,
'/api/route-headers'
,
...
@@ -331,7 +310,6 @@ describe('Middleware Non-ASCII Headers', () => {
...
@@ -331,7 +310,6 @@ describe('Middleware Non-ASCII Headers', () => {
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
status
).
toBe
(
200
)
const
body
=
await
res
.
json
()
const
body
=
await
res
.
json
()
// Intentional percent-encoding should be preserved
expect
(
body
[
'x-path'
]).
toBe
(
'/hello%2Fworld'
)
expect
(
body
[
'x-path'
]).
toBe
(
'/hello%2Fworld'
)
expect
(
body
[
'x-query'
]).
toBe
(
'foo%20bar'
)
expect
(
body
[
'x-query'
]).
toBe
(
'foo%20bar'
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment