0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-server-non-utf8-header.js
Arsalan Ahmad 6e90fed8c3
http: handle multi-value content-disposition header
Headers in nodejs can be arrays and current workaround for
content-disposition header do not take this into account.
This change fixes that and makes sure array values are handled
properly.

PR-URL: https://github.com/nodejs/node/pull/50977
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-12-11 08:41:23 +00:00

70 lines
1.9 KiB
JavaScript

'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();
}));
});
}));
}