Skip to content

Commit 4e38dee

Browse files
ArsalanDotMerichardlau
authored andcommitted
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: #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>
1 parent c7350c2 commit 4e38dee

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎lib/_http_outgoing.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,14 @@ function processHeader(self, state, key, value, validate) {
556556
// https://www.rfc-editor.org/rfc/rfc6266#section-4.3
557557
// Refs: https://github.com/nodejs/node/pull/46528
558558
if(isContentDispositionField(key)&&self._contentLength){
559-
value=Buffer.from(value,'latin1');
559+
// The value could be an array here
560+
if(ArrayIsArray(value)){
561+
for(leti=0;i<value.length;i++){
562+
value[i]=Buffer.from(value[i],'latin1');
563+
}
564+
}else{
565+
value=Buffer.from(value,'latin1');
566+
}
560567
}
561568

562569
if(ArrayIsArray(value)){

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

Lines 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+
constserver=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
constserver=http.createServer(common.mustCall((req,res)=>{
3152
res.writeHead(200,[

0 commit comments

Comments
 (0)