GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: handle multi-value content-disposition header · nodejs/node@0092358

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • _http_outgoing.js
  • test/parallel
    • test-http-server-non-utf8-header.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,14 @@ function processHeader(self, state, key, value, validate) {
552552
// https://www.rfc-editor.org/rfc/rfc6266#section-4.3
553553
// Refs: https://github.com/nodejs/node/pull/46528
554554
if (isContentDispositionField(key) && self._contentLength) {
555-
value = Buffer.from(value, 'latin1');
555+
// The value could be an array here
556+
if (ArrayIsArray(value)) {
557+
for (let i = 0; i < value.length; i++) {
558+
value[i] = Buffer.from(value[i], 'latin1');
559+
}
560+
} else {
561+
value = Buffer.from(value, 'latin1');
562+
}
556563
}
557564

558565
if (ArrayIsArray(value)) {
Collapse file

‎test/parallel/test-http-server-non-utf8-header.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-server-non-utf8-header.js
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ const nonUtf8ToLatin1 = Buffer.from(nonUtf8Header).toString('latin1');
2626
}));
2727
}
2828

29+
{
30+
// Test multi-value header
31+
const server = http.createServer(common.mustCall((req, res) => {
32+
res.writeHead(200, [
33+
'content-disposition',
34+
[Buffer.from(nonUtf8Header).toString('binary')],
35+
]);
36+
res.end('hello');
37+
}));
38+
39+
server.listen(0, common.mustCall(() => {
40+
http.get({ port: server.address().port }, (res) => {
41+
assert.strictEqual(res.statusCode, 200);
42+
assert.strictEqual(res.headers['content-disposition'], nonUtf8ToLatin1);
43+
res.resume().on('end', common.mustCall(() => {
44+
server.close();
45+
}));
46+
});
47+
}));
48+
}
49+
2950
{
3051
const server = http.createServer(common.mustCall((req, res) => {
3152
res.writeHead(200, [

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.