fix: implement 'login' event for net.ClientRequest (#21096)

This commit is contained in:
Jeremy Apthorp 2019-11-14 10:01:18 -08:00 committed by GitHub
parent 878ab916d2
commit 4f1536479e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 445 additions and 38 deletions

View file

@ -247,22 +247,11 @@ class ClientRequest extends EventEmitter {
})
urlRequest.on('login', (event, authInfo, callback) => {
this.emit('login', authInfo, (username, password) => {
// If null or undefined username/password, force to empty string.
if (username === null || username === undefined) {
username = ''
}
if (typeof username !== 'string') {
throw new Error('username must be a string')
}
if (password === null || password === undefined) {
password = ''
}
if (typeof password !== 'string') {
throw new Error('password must be a string')
}
callback(username, password)
})
const handled = this.emit('login', authInfo, callback)
if (!handled) {
// If there were no listeners, cancel the authentication request.
callback()
}
})
if (callback) {