fix: recognize 'undefined' header value in ClientRequest (#41615)

Co-authored-by: zowu <luke.wu@nokia-sbell.com>
This commit is contained in:
daihere1993 2024-03-28 07:46:07 +08:00 committed by GitHub
parent 08241669bc
commit 72c2b9e862
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 18 deletions

View file

@ -616,6 +616,25 @@ describe('net module (session)', () => {
});
}).to.throw('`partition` should be a string');
});
it('should throw if given a header value that is empty(null/undefined)', () => {
const emptyHeaderValues = [null, undefined];
const errorMsg = '`value` required in setHeader("foo", value)';
for (const emptyValue of emptyHeaderValues) {
expect(() => {
net.request({
url: 'https://foo',
headers: { foo: emptyValue as any }
} as any);
}).to.throw(errorMsg);
const request = net.request({ url: 'https://foo' });
expect(() => {
request.setHeader('foo', emptyValue as any);
}).to.throw(errorMsg);
}
});
});
describe('net.fetch', () => {