-
Notifications
You must be signed in to change notification settings - Fork 30.3k
/
Copy pathtest-http-server-non-utf8-header.js
69 lines (62 loc) · 1.87 KB
/
test-http-server-non-utf8-header.js
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
'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');
const nonUtf8Header = 'bår';
const nonUtf8ToLatin1 = Buffer.from(nonUtf8Header).toString('latin1');
{
const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200, [
'content-disposition',
Buffer.from(nonUtf8Header).toString('binary'),
]);
res.end('hello');
}));
server.listen(0, common.mustCall(() => {
http.get({ port: server.address().port }, (res) => {
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.headers['content-disposition'], nonUtf8ToLatin1);
res.resume().on('end', common.mustCall(() => {
server.close();
}));
});
}));
}
{
// Test multi-value header
const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200, [
'content-disposition',
[Buffer.from(nonUtf8Header).toString('binary')],
]);
res.end('hello');
}));
server.listen(0, common.mustCall(() => {
http.get({ port: server.address().port }, (res) => {
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.headers['content-disposition'], nonUtf8ToLatin1);
res.resume().on('end', common.mustCall(() => {
server.close();
}));
});
}));
}
{
const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200, [
'Content-Length', '5',
'content-disposition',
Buffer.from(nonUtf8Header).toString('binary'),
]);
res.end('hello');
}));
server.listen(0, common.mustCall(() => {
http.get({ port: server.address().port }, (res) => {
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.headers['content-disposition'], nonUtf8ToLatin1);
res.resume().on('end', common.mustCall(() => {
server.close();
}));
});
}));
}