fix
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { byteStringResponseHeaders } from './response-headers.js'
|
||||
|
||||
test('заголовки с кириллицей совместимы с Headers, обычные значения сохраняются', () => {
|
||||
const original = {
|
||||
'X-Name': ['пример'],
|
||||
Location: ['https://media.test/папка/трек.mp3?name=%D0%B0'],
|
||||
'Content-Disposition': ['attachment; filename="пример.mp3"'],
|
||||
'Content-Length': ['1024'],
|
||||
'Content-Type': ['audio/wav'],
|
||||
'X-Latin': ['caf\u00e9'],
|
||||
'Set-Cookie': ['a=1', 'b=2'],
|
||||
}
|
||||
const result = byteStringResponseHeaders(original)
|
||||
const headers = new Headers(Object.fromEntries(Object.entries(result).map(([name, values]) => [name, values.join(', ')])))
|
||||
assert.equal(headers.get('x-name'), encodeURIComponent('пример'))
|
||||
assert.equal(headers.get('location'), new URL(original.Location[0]!).href)
|
||||
assert.equal(result['Content-Disposition']![0], `attachment; filename="${encodeURIComponent('пример')}.mp3"`)
|
||||
for (const name of ['Content-Length', 'Content-Type', 'X-Latin', 'Set-Cookie'] as const)
|
||||
assert.deepEqual(result[name], original[name])
|
||||
assert.equal(original['X-Name'][0], 'пример')
|
||||
assert.deepEqual(byteStringResponseHeaders(), {})
|
||||
})
|
||||
Reference in New Issue
Block a user