| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,6 +101,10 @@ function isCookieField(s) { | |||
| 101 | 101 | return s.length === 6 && StringPrototypeToLowerCase(s) === 'cookie'; | |
| 102 | 102 | } | |
| 103 | 103 | ||
| 104 | + function isContentDispositionField(s) { | ||
| 105 | + return s.length === 19 && StringPrototypeToLowerCase(s) === 'content-disposition'; | ||
| 106 | + } | ||
| 107 | + | ||
| 104 | 108 | function OutgoingMessage() { | |
| 105 | 109 | Stream.call(this); | |
| 106 | 110 | ||
@@ -570,6 +574,15 @@ function _storeHeader(firstLine, headers) { | |||
| 570 | 574 | function processHeader(self, state, key, value, validate) { | |
| 571 | 575 | if (validate) | |
| 572 | 576 | validateHeaderName(key); | |
| 577 | + | ||
| 578 | + // If key is content-disposition and there is content-length | ||
| 579 | + // encode the value in latin1 | ||
| 580 | + // https://www.rfc-editor.org/rfc/rfc6266#section-4.3 | ||
| 581 | + // Refs: https://github.com/nodejs/node/pull/46528 | ||
| 582 | + if (isContentDispositionField(key) && self._contentLength) { | ||
| 583 | + value = Buffer.from(value, 'latin1'); | ||
| 584 | + } | ||
| 585 | + | ||
| 573 | 586 | if (ArrayIsArray(value)) { | |
| 574 | 587 | if ( | |
| 575 | 588 | (value.length < 2 || !isCookieField(key)) && | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,48 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const http = require('http'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const nonUtf8Header = 'bår'; | ||
| 7 | + const nonUtf8ToLatin1 = Buffer.from(nonUtf8Header).toString('latin1'); | ||
| 8 | + | ||
| 9 | + { | ||
| 10 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 11 | + res.writeHead(200, [ | ||
| 12 | + 'content-disposition', | ||
| 13 | + Buffer.from(nonUtf8Header).toString('binary'), | ||
| 14 | + ]); | ||
| 15 | + res.end('hello'); | ||
| 16 | + })); | ||
| 17 | + | ||
| 18 | + server.listen(0, common.mustCall(() => { | ||
| 19 | + http.get({ port: server.address().port }, (res) => { | ||
| 20 | + assert.strictEqual(res.statusCode, 200); | ||
| 21 | + assert.strictEqual(res.headers['content-disposition'], nonUtf8ToLatin1); | ||
| 22 | + res.resume().on('end', common.mustCall(() => { | ||
| 23 | + server.close(); | ||
| 24 | + })); | ||
| 25 | + }); | ||
| 26 | + })); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + { | ||
| 30 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 31 | + res.writeHead(200, [ | ||
| 32 | + 'Content-Length', '5', | ||
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments