Skip to content

Commit f6683aa

Browse files
committed
Add a test case for invalid headers
See feae6d6.
1 parent 13b230b commit f6683aa

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ export default class TestServer {
117117
res.end('fake gzip string');
118118
}
119119

120+
if (p === '/invalid-header') {
121+
res.setHeader('Content-Type', 'text/plain');
122+
res.writeHead(200);
123+
// HACK: add a few invalid headers to the generated header string before
124+
// it is actually sent to the socket.
125+
res._header = res._header.replace(/\r\n$/, [
126+
'Invalid-Header : abc\r\n',
127+
'Invalid-Header-Value: \x07k\r\n',
128+
'Set-Cookie: \x07k\r\n',
129+
'Set-Cookie: \x07kk\r\n',
130+
].join('') + '\r\n');
131+
res.end('hello world\n');
132+
}
133+
120134
if (p === '/timeout') {
121135
setTimeout(function() {
122136
res.statusCode = 200;

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,20 @@ describe('node-fetch', () => {
477477
});
478478
});
479479

480+
it('should ignore invalid headers', function() {
481+
const url = `${base}invalid-header`;
482+
return fetch(url).then(res => {
483+
expect(res.headers.get('Invalid-Header')).to.be.null;
484+
expect(res.headers.get('Invalid-Header-Value')).to.be.null;
485+
expect(res.headers.get('Set-Cookie')).to.be.null;
486+
expect(Array.from(res.headers.keys()).length).to.equal(4);
487+
expect(res.headers.has('Connection')).to.be.true;
488+
expect(res.headers.has('Content-Type')).to.be.true;
489+
expect(res.headers.has('Date')).to.be.true;
490+
expect(res.headers.has('Transfer-Encoding')).to.be.true;
491+
});
492+
});
493+
480494
it('should handle client-error response', function() {
481495
const url = `${base}error/400`;
482496
return fetch(url).then(res => {

0 commit comments

Comments
 (0)