-
-
Notifications
You must be signed in to change notification settings - Fork 759
Expand file tree
/
Copy pathencoding.js
More file actions
83 lines (64 loc) · 2.83 KB
/
encoding.js
File metadata and controls
83 lines (64 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict'
const { test } = require('node:test')
const assert = require('node:assert')
const { createServer } = require('node:http')
const { once } = require('node:events')
const { fetch } = require('../..')
const zlib = require('node:zlib')
const { closeServerAsPromise } = require('../utils/node-http')
const skip = process.versions.node.split('.').map(Number)[0] === 20 && process.platform === 'darwin'
test('content-encoding header is case-iNsENsITIve', { skip }, async (t) => {
const contentCodings = 'GZiP, bR'
const text = 'Hello, World!'
const gzipBrotliText = Buffer.from('CxCAH4sIAAAAAAAAA/NIzcnJ11EIzy/KSVEEANDDSuwNAAAAAw==', 'base64')
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
res.setHeader('Content-Encoding', contentCodings)
res.setHeader('Content-Type', 'text/plain')
res.write(gzipBrotliText)
res.end()
}).listen(0)
t.after(closeServerAsPromise(server))
await once(server, 'listening')
const response = await fetch(`http://localhost:${server.address().port}`)
assert.strictEqual(await response.text(), text)
assert.strictEqual(response.headers.get('content-encoding'), contentCodings)
await t.completed
})
test('response decompression according to content-encoding should be handled in a correct order', async (t) => {
const contentCodings = 'deflate, gzip'
const text = 'Hello, World!'
const gzipDeflateText = Buffer.from('H4sIAAAAAAAAA6uY89nj7MmT1wM5zuuf8gxkYZCfx5IFACQ8u/wVAAAA', 'base64')
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
res.setHeader('Content-Encoding', contentCodings)
res.setHeader('Content-Type', 'text/plain')
res.write(gzipDeflateText)
res.end()
}).listen(0)
t.after(closeServerAsPromise(server))
await once(server, 'listening')
const response = await fetch(`http://localhost:${server.address().port}`)
assert.strictEqual(await response.text(), text)
await t.completed
})
test('should decompress zstandard response',
{ skip: typeof zlib.createZstdDecompress !== 'function' },
async (t) => {
const contentCodings = 'zstd'
const text = 'Hello, World!'
const zstdText = Buffer.from('KLUv/QBYaQAASGVsbG8sIFdvcmxkIQ==', 'base64')
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
res.setHeader('Content-Encoding', contentCodings)
res.setHeader('Content-Type', 'text/plain')
res.write(zstdText)
res.end()
}
).listen(0)
t.after(closeServerAsPromise(server))
await once(server, 'listening')
const url = `http://localhost:${server.address().port}`
const response = await fetch(url)
assert.strictEqual(await response.text(), text)
assert.strictEqual(response.headers.get('content-encoding'), contentCodings)
assert.strictEqual(response.headers.get('content-type'), 'text/plain')
await t.completed
})