fix(xo-server): HTTP proxy support for consoles

Introduced by 6c16055a1

Fixes #7476
This commit is contained in:
Julien Fontanet
2024-03-18 09:13:44 +01:00
parent 215577b313
commit e8c9e620ca

View File

@@ -51,6 +51,7 @@ import { Strategy as LocalStrategy } from 'passport-local'
import transportConsole from '@xen-orchestra/log/transports/console'
import { configure } from '@xen-orchestra/log/configure'
import { generateToken } from './utils.mjs'
import { ProxyAgent } from 'proxy-agent'
// ===================================================================
@@ -752,9 +753,18 @@ const setUpConsoleProxy = (webServer, xo, useForwardedHeaders) => {
const xapi = vm.$xapi
const vmConsole = xapi.getVmConsole(id)
const serverId = xo.getXenServerIdByObject(id, ['VM', 'VM-controller'])
const server = await xo.getXenServer(serverId)
const agent =
server.httpProxy &&
new ProxyAgent({
getProxyForUrl: () => httpProxy,
rejectUnauthorized: !server.allowUnauthorized,
})
// FIXME: lost connection due to VM restart is not detected.
webSocketServer.handleUpgrade(req, socket, head, connection => {
proxyConsole(connection, vmConsole, xapi.sessionId, xapi.httpAgent)
proxyConsole(connection, vmConsole, xapi.sessionId, agent)
})
} catch (error) {
try {