Check name directly instead of arguments length

This commit is contained in:
Kevin Sawicki 2017-03-30 12:37:40 -07:00
parent a2588c1fd9
commit fcb7cbc54a
2 changed files with 22 additions and 2 deletions

View file

@ -259,7 +259,7 @@ class ClientRequest extends EventEmitter {
} }
getHeader (name) { getHeader (name) {
if (arguments.length < 1) { if (name == null) {
throw new Error('`name` is required for getHeader(name).') throw new Error('`name` is required for getHeader(name).')
} }
@ -272,7 +272,7 @@ class ClientRequest extends EventEmitter {
} }
removeHeader (name) { removeHeader (name) {
if (arguments.length < 1) { if (name == null) {
throw new Error('`name` is required for removeHeader(name).') throw new Error('`name` is required for removeHeader(name).')
} }

View file

@ -960,6 +960,26 @@ describe('net module', function () {
}, 'redirect mode should be one of follow, error or manual') }, '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) { it('should follow redirect when no redirect mode is provided', function (done) {
const requestUrl = '/301' const requestUrl = '/301'
server.on('request', function (request, response) { server.on('request', function (request, response) {