diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index a498d4ac7..2a8712878 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -205,23 +205,26 @@ module.exports = function(RED) { } } } - if (this.credentials) { + var parsedURL = new URL(url) + this.credentials = this.credentials || {} + if (parsedURL.username && !this.credentials.user) { + this.credentials.user = parsedURL.username + } + if (parsedURL.password && !this.credentials.password) { + this.credentials.password = parsedURL.password + } + if (Object.keys(this.credentials).length != 0) { if (this.authType === "basic") { // Workaround for https://github.com/sindresorhus/got/issues/1169 var cred = "" - var parsedURL = new URL(url) if (this.credentials.user) { // opts.username = this.credentials.user; cred = this.credentials.user - } else if (parsedURL.username) { - cred = parsedURL.username - } + } if (this.credentials.password) { // opts.password = this.credentials.password; cred += ":" + this.credentials.password - } else if (parsedURL.password) { - cred += ":" + parsedURL.password - } + } // build own basic auth header opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64"); } else if (this.authType === "digest") {