feat(xen-api): support pathname in URL

Fixes #6174
This commit is contained in:
Julien Fontanet 2022-04-02 20:01:09 +02:00
parent e44857c023
commit d2a13f531a
5 changed files with 11 additions and 8 deletions

View File

@ -28,5 +28,5 @@
> >
> In case of conflict, the highest (lowest in previous list) `$version` wins. > In case of conflict, the highest (lowest in previous list) `$version` wins.
- xen-api patch - xen-api minor
- @xen-orchestra/proxy patch - @xen-orchestra/proxy patch

View File

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

View File

@ -1,5 +1,6 @@
import httpRequestPlus from 'http-request-plus' import httpRequestPlus from 'http-request-plus'
import { format, parse } from 'json-rpc-protocol' import { format, parse } from 'json-rpc-protocol'
import { join } from 'path'
import XapiError from '../_XapiError' import XapiError from '../_XapiError'
@ -16,7 +17,7 @@ export default ({ secureOptions, url, agent }) => {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
path: '/jsonrpc', pathname: join(url.pathname, 'jsonrpc'),
agent, agent,
}) })
.readAll('utf8') .readAll('utf8')

View File

@ -1,4 +1,5 @@
import { createClient, createSecureClient } from 'xmlrpc' import { createClient, createSecureClient } from 'xmlrpc'
import { join } from 'path'
import { promisify } from 'promise-toolbox' import { promisify } from 'promise-toolbox'
import XapiError from '../_XapiError' import XapiError from '../_XapiError'
@ -70,13 +71,13 @@ const parseResult = result => {
throw new UnsupportedTransport() throw new UnsupportedTransport()
} }
export default ({ secureOptions, url: { hostname, port, protocol }, agent }) => { export default ({ secureOptions, url: { hostname, port, protocol, pathname }, agent }) => {
const secure = protocol === 'https:' const secure = protocol === 'https:'
const client = (secure ? createSecureClient : createClient)({ const client = (secure ? createSecureClient : createClient)({
...(secure ? secureOptions : undefined), ...(secure ? secureOptions : undefined),
agent, agent,
host: hostname, host: hostname,
path: '/json', path: join(pathname, 'json'),
port, port,
}) })
const call = promisify(client.methodCall, client) const call = promisify(client.methodCall, client)

View File

@ -30,12 +30,13 @@ const parseResult = result => {
return result.Value return result.Value
} }
export default ({ secureOptions, url: { hostname, port, protocol }, agent }) => { export default ({ secureOptions, url: { hostname, pathname, port, protocol }, agent }) => {
const secure = protocol === 'https:' const secure = protocol === 'https:'
const client = (secure ? createSecureClient : createClient)({ const client = (secure ? createSecureClient : createClient)({
...(secure ? secureOptions : undefined), ...(secure ? secureOptions : undefined),
agent, agent,
host: hostname, host: hostname,
pathname,
port, port,
}) })
const call = promisify(client.methodCall, client) const call = promisify(client.methodCall, client)