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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_http_outgoing.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -552,7 +552,14 @@ function processHeader(self, state, key, value, validate) { |
552 | 552 | // https://www.rfc-editor.org/rfc/rfc6266#section-4.3 |
553 | 553 | // Refs: https://github.com/nodejs/node/pull/46528 |
554 | 554 | 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 | + } |
556 | 563 | } |
557 | 564 |
|
558 | 565 | if (ArrayIsArray(value)) { |
|
Collapse file
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 number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,27 @@ const nonUtf8ToLatin1 = Buffer.from(nonUtf8Header).toString('latin1'); |
26 | 26 | })); |
27 | 27 | } |
28 | 28 |
|
| 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 | + |
29 | 50 | { |
30 | 51 | const server = http.createServer(common.mustCall((req, res) => { |
31 | 52 | res.writeHead(200, [ |
|