diff --git a/lib/_http_client.js b/lib/_http_client.js index 2002d2bc8ea..b4057a6e507 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -102,7 +102,7 @@ function ClientRequest(options, cb) { if (options.auth && !this.getHeader('Authorization')) { //basic auth this.setHeader('Authorization', 'Basic ' + - new Buffer(options.auth).toString('base64')); + Buffer.from(options.auth).toString('base64')); } if (method === 'GET' || diff --git a/test/parallel/test-http-auth-number.js b/test/parallel/test-http-auth-number.js new file mode 100644 index 00000000000..f2d76482947 --- /dev/null +++ b/test/parallel/test-http-auth-number.js @@ -0,0 +1,13 @@ +'use strict'; + +require('../common'); +const http = require('http'); +const url = require('url'); +const assert = require('assert'); + +const opts = url.parse('http://127.0.0.1:8180'); +opts.auth = 100; + +assert.throws(() => { + http.get(opts); +}, /^TypeError: "value" argument must not be a number$/);