Better handling of hostname/ip:port format (#837)
* Better handling of hostname/ip:port format * Updated test
This commit is contained in:
committed by
GitHub
parent
6f4fb16200
commit
1261e60d41
@ -336,16 +336,14 @@ class ConnectionPool {
|
||||
// if we encounter the second case, we should
|
||||
// use the hostname instead of the ip
|
||||
var address = node.http.publish_address
|
||||
const hostAndIpRegex = /^[a-z0-9_.-]*\/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/gi
|
||||
const match = address.match(hostAndIpRegex)
|
||||
if (match !== null) {
|
||||
const ipRegex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
|
||||
const ip = address.match(ipRegex)[0]
|
||||
// extract the hostname, the -1 at the end removes the final /
|
||||
const hostname = address.slice(0, address.indexOf(ip) - 1)
|
||||
const port = address.split(':')[1]
|
||||
const parts = address.split('/')
|
||||
// the url is in the form of hostname/ip:port
|
||||
if (parts.length > 1) {
|
||||
const hostname = parts[0]
|
||||
const port = parts[1].match(/((?::))(?:[0-9]+)$/g)[0].slice(1)
|
||||
address = `${hostname}:${port}`
|
||||
}
|
||||
|
||||
address = address.slice(0, 4) === 'http'
|
||||
? address
|
||||
: `${protocol}//${address}`
|
||||
|
||||
Reference in New Issue
Block a user