Check name directly instead of arguments length
This commit is contained in:
parent
a2588c1fd9
commit
fcb7cbc54a
2 changed files with 22 additions and 2 deletions
|
@ -259,7 +259,7 @@ class ClientRequest extends EventEmitter {
|
|||
}
|
||||
|
||||
getHeader (name) {
|
||||
if (arguments.length < 1) {
|
||||
if (name == null) {
|
||||
throw new Error('`name` is required for getHeader(name).')
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,7 @@ class ClientRequest extends EventEmitter {
|
|||
}
|
||||
|
||||
removeHeader (name) {
|
||||
if (arguments.length < 1) {
|
||||
if (name == null) {
|
||||
throw new Error('`name` is required for removeHeader(name).')
|
||||
}
|
||||
|
||||
|
|
|
@ -960,6 +960,26 @@ describe('net module', function () {
|
|||
}, 'redirect mode should be one of follow, error or manual')
|
||||
})
|
||||
|
||||
it('should throw when calling getHeader without a name', function () {
|
||||
assert.throws(function () {
|
||||
net.request({url: `${server.url}/requestUrl`}).getHeader()
|
||||
}, /`name` is required for getHeader\(name\)\./)
|
||||
|
||||
assert.throws(function () {
|
||||
net.request({url: `${server.url}/requestUrl`}).getHeader(null)
|
||||
}, /`name` is required for getHeader\(name\)\./)
|
||||
})
|
||||
|
||||
it('should throw when calling removeHeader without a name', function () {
|
||||
assert.throws(function () {
|
||||
net.request({url: `${server.url}/requestUrl`}).removeHeader()
|
||||
}, /`name` is required for removeHeader\(name\)\./)
|
||||
|
||||
assert.throws(function () {
|
||||
net.request({url: `${server.url}/requestUrl`}).removeHeader(null)
|
||||
}, /`name` is required for removeHeader\(name\)\./)
|
||||
})
|
||||
|
||||
it('should follow redirect when no redirect mode is provided', function (done) {
|
||||
const requestUrl = '/301'
|
||||
server.on('request', function (request, response) {
|
||||
|
|
Loading…
Reference in a new issue