Commit 41fd30ef authored by Jiachi Liu's avatar Jiachi Liu

update test

parent b02ac1bd
......@@ -946,6 +946,8 @@ export default abstract class Server<
// In minimal mode (Vercel), decode percent-encoded header values.
// Middleware encodes non-ASCII characters for safe HTTP transport,
// and we decode them here to restore the original values.
// Note: decodeHeaderValue is safe - it only decodes valid percent-encoded
// sequences and returns the original value if decoding fails.
if (this.minimalMode) {
for (const key of Object.keys(req.headers)) {
const value = req.headers[key]
......
......@@ -187,31 +187,31 @@ describe('Middleware Non-ASCII Headers', () => {
expect(headers['x-city']).toBe('São Paulo')
})
// Test for LOCAL scenario: when headers are sent as proper Latin-1 (not Mojibake)
// This happens when:
// - A local proxy (nginx, etc.) adds headers with non-ASCII
// - Node.js fetch/http client sends headers (converts to Latin-1)
// Unlike CDN scenario, these arrive as single-byte Latin-1, not UTF-8 Mojibake
it('should handle Latin-1 encoded headers (local proxy scenario)', async () => {
// When fetchViaHTTP sends "Montréal", it encodes as Latin-1:
// "é" becomes single byte 0xE9 (not UTF-8's 0xC3 0xA9)
// This simulates a local proxy adding headers
// Test for headers that arrive as proper UTF-8 (not Mojibake)
// In HTTP/2 environments (like Vercel deployment), headers are transmitted as UTF-8.
// When the server interprets UTF-8 bytes as Latin-1, we get Mojibake.
// This test verifies that both scenarios work:
// - Local: UTF-8 headers might arrive as Mojibake (Node.js interprets as Latin-1)
// - Deploy: UTF-8 headers arrive correctly or as Mojibake depending on transport
it('should handle UTF-8 encoded headers (proxy scenario)', async () => {
// Send headers as Mojibake to simulate what happens when UTF-8 bytes
// are interpreted as Latin-1 by the server (common in CDN/proxy scenarios)
const res = await fetchViaHTTP(
next.url,
'/api/headers',
{},
{
headers: {
'x-city': 'Montréal', // Latin-1: é = 0xE9
'x-region': 'Île-de-France',
'x-country': 'Österreich',
'x-city': toMojibake('Montréal'),
'x-region': toMojibake('Île-de-France'),
'x-country': toMojibake('Österreich'),
},
}
)
expect(res.status).toBe(200)
const headers = await res.json()
// These should be preserved correctly through middleware
// These should be decoded correctly through middleware
expect(headers['x-city']).toBe('Montréal')
expect(headers['x-region']).toBe('Île-de-France')
expect(headers['x-country']).toBe('Österreich')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment