Skip to content

Commit

Permalink
fix: do not instantiate a proxy for each request
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Oct 27, 2021
1 parent 9b52ab2 commit be4c7b6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [Jobs] Ability to copy a job ID (PR [#5951](/~https://github.com/vatesfr/xen-orchestra/pull/5951))
- [Host/advanced] Add button to enable/disable the host (PR [#5952](/~https://github.com/vatesfr/xen-orchestra/pull/5952))
- [VM/export] Ability to copy the export URL (PR [#5948](/~https://github.com/vatesfr/xen-orchestra/pull/5948))
- [XenApi] Ability to set a http proxy between XO and the server
- [Servers] Ability to use an HTTP proxy between XO and a server

### Bug fixes

Expand Down
6 changes: 5 additions & 1 deletion packages/xen-api/src/transports/json-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import UnsupportedTransport from './_UnsupportedTransport'

// /~https://github.com/xenserver/xenadmin/blob/0df39a9d83cd82713f32d24704852a0fd57b8a64/XenModel/XenAPI/Session.cs#L403-L433
export default ({ secureOptions, url, httpProxy }) => {
let agent
if (httpProxy !== undefined) {
agent = new ProxyAgent(httpProxy)
}
return (method, args) =>
httpRequestPlus
.post(url, {
...secureOptions,
agent: httpProxy !== undefined ? new ProxyAgent(httpProxy) : undefined,
body: format.request(0, method, args),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
path: '/jsonrpc',
agent,
})
.readAll('utf8')
.then(
Expand Down
6 changes: 5 additions & 1 deletion packages/xen-api/src/transports/xml-rpc-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ const parseResult = result => {

export default ({ secureOptions, url: { hostname, port, protocol }, httpProxy }) => {
const secure = protocol === 'https:'
let agent
if (httpProxy !== undefined) {
agent = new ProxyAgent(httpProxy)
}
const client = (secure ? createSecureClient : createClient)({
...(secure ? secureOptions : undefined),
agent: httpProxy !== undefined ? new ProxyAgent(httpProxy) : undefined,
agent,
host: hostname,
path: '/json',
port,
Expand Down
7 changes: 5 additions & 2 deletions packages/xen-api/src/transports/xml-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ const parseResult = result => {

export default ({ secureOptions, url: { hostname, port, protocol, httpProxy } }) => {
const secure = protocol === 'https:'

let agent
if (httpProxy !== undefined) {
agent = new ProxyAgent(httpProxy)
}
const client = (secure ? createSecureClient : createClient)({
...(secure ? secureOptions : undefined),
agent: httpProxy !== undefined ? new ProxyAgent(httpProxy) : undefined,
agent,
host: hostname,
port,
})
Expand Down

0 comments on commit be4c7b6

Please sign in to comment.