fix(xen-api/transports/json-rpc): fix IPv6 address support

Introduced by ab96c549a
This commit is contained in:
Julien Fontanet
2023-06-22 11:08:50 +02:00
parent 41bb16ca30
commit b82b676fdb
4 changed files with 10 additions and 5 deletions

View File

@@ -11,6 +11,8 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Settings/Servers] Fix connecting using an explicit IPv6 address
### Packages to release
> When modifying a package, add it here with its release type.
@@ -27,4 +29,6 @@
<!--packages-start-->
- xen-api patch
<!--packages-end-->

View File

@@ -11,7 +11,7 @@ const data = {
protocol: 'https:',
},
'[::1]': {
hostname: '::1',
hostname: '[::1]',
pathname: '/',
protocol: 'https:',
},

View File

@@ -1,4 +1,4 @@
const URL_RE = /^(?:(https?:)\/*)?(?:(([^:]*)(?::([^@]*))?)@)?(?:\[([^\]]+)\]|([^:/]+))(?::([0-9]+))?(\/[^?#]*)?$/
const URL_RE = /^(?:(https?:)\/*)?(?:(([^:]*)(?::([^@]*))?)@)?(\[[^\]]+\]|[^:/]+)(?::([0-9]+))?(\/[^?#]*)?$/
export default url => {
const matches = URL_RE.exec(url)
@@ -6,8 +6,7 @@ export default url => {
throw new Error('invalid URL: ' + url)
}
const [, protocol = 'https:', auth, username = '', password = '', ipv6, hostname = ipv6, port, pathname = '/'] =
matches
const [, protocol = 'https:', auth, username = '', password = '', hostname, port, pathname = '/'] = matches
const parsedUrl = {
protocol,
hostname,

View File

@@ -30,12 +30,14 @@ const parseResult = result => {
return result.Value
}
const removeBrackets = hostname => (hostname[0] === '[' ? hostname.slice(1, -1) : hostname)
export default ({ secureOptions, url: { hostname, pathname, port, protocol }, agent }) => {
const secure = protocol === 'https:'
const client = (secure ? createSecureClient : createClient)({
...(secure ? secureOptions : undefined),
agent,
host: hostname,
host: removeBrackets(hostname),
pathname,
port,
})