Merge pull request #237 from vatesfr/http-proxy
HTTP proxy support (fix vatesfr/xo-web#737).
This commit is contained in:
commit
558956bf55
@ -111,6 +111,7 @@
|
|||||||
"passport": "^0.3.0",
|
"passport": "^0.3.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"promise-toolbox": "^0.1.0",
|
"promise-toolbox": "^0.1.0",
|
||||||
|
"proxy-agent": "^2.0.0",
|
||||||
"proxy-http-request": "0.1.0",
|
"proxy-http-request": "0.1.0",
|
||||||
"redis": "^2.0.1",
|
"redis": "^2.0.1",
|
||||||
"schema-inspector": "^1.5.1",
|
"schema-inspector": "^1.5.1",
|
||||||
|
@ -107,6 +107,12 @@ http:
|
|||||||
proxies:
|
proxies:
|
||||||
# '/any/url': 'http://localhost:54722'
|
# '/any/url': 'http://localhost:54722'
|
||||||
|
|
||||||
|
# HTTP proxy configuration used by xo-server to fetch resources on the
|
||||||
|
# Internet.
|
||||||
|
#
|
||||||
|
# See: https://github.com/TooTallNate/node-proxy-agent#maps-proxy-protocols-to-httpagent-implementations
|
||||||
|
#httpProxy: 'http://jsmith:qwerty@proxy.lan:3128'
|
||||||
|
|
||||||
#=====================================================================
|
#=====================================================================
|
||||||
|
|
||||||
# Connection to the Redis server.
|
# Connection to the Redis server.
|
||||||
|
12
src/http-proxy.js
Normal file
12
src/http-proxy.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import ProxyAgent from 'proxy-agent'
|
||||||
|
|
||||||
|
export let agent
|
||||||
|
|
||||||
|
export function setup (uri) {
|
||||||
|
agent = uri != null
|
||||||
|
? new ProxyAgent(uri)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const { env } = process
|
||||||
|
setup(env.http_proxy || env.HTTP_PROXY)
|
@ -37,6 +37,9 @@ import Api from './api'
|
|||||||
import WebServer from 'http-server-plus'
|
import WebServer from 'http-server-plus'
|
||||||
import wsProxy from './ws-proxy'
|
import wsProxy from './ws-proxy'
|
||||||
import Xo from './xo'
|
import Xo from './xo'
|
||||||
|
import {
|
||||||
|
setup as setupHttpProxy
|
||||||
|
} from './http-proxy'
|
||||||
import {
|
import {
|
||||||
createRawObject,
|
createRawObject,
|
||||||
forEach,
|
forEach,
|
||||||
@ -600,6 +603,10 @@ export default async function main (args) {
|
|||||||
warn('Failed to change user/group:', error)
|
warn('Failed to change user/group:', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.httpProxy) {
|
||||||
|
setupHttpProxy(config.httpProxy)
|
||||||
|
}
|
||||||
|
|
||||||
// Creates main object.
|
// Creates main object.
|
||||||
const xo = new Xo(config)
|
const xo = new Xo(config)
|
||||||
|
|
||||||
|
13
src/xapi.js
13
src/xapi.js
@ -17,14 +17,18 @@ import {
|
|||||||
wrapError as wrapXapiError,
|
wrapError as wrapXapiError,
|
||||||
Xapi as XapiBase
|
Xapi as XapiBase
|
||||||
} from 'xen-api'
|
} from 'xen-api'
|
||||||
|
import {
|
||||||
|
satisfies as versionSatisfies
|
||||||
|
} from 'semver'
|
||||||
|
|
||||||
import httpRequest from './http-request'
|
import httpRequest from './http-request'
|
||||||
import {
|
import {
|
||||||
debounce,
|
debounce,
|
||||||
deferrable
|
deferrable
|
||||||
} from './decorators'
|
} from './decorators'
|
||||||
import { satisfies as versionSatisfies } from 'semver'
|
import {
|
||||||
|
agent as httpProxy
|
||||||
|
} from './http-proxy'
|
||||||
import {
|
import {
|
||||||
bufferToStream,
|
bufferToStream,
|
||||||
camelToSnakeCase,
|
camelToSnakeCase,
|
||||||
@ -447,7 +451,8 @@ export default class Xapi extends XapiBase {
|
|||||||
@debounce(24 * 60 * 60 * 1000)
|
@debounce(24 * 60 * 60 * 1000)
|
||||||
async _getXenUpdates () {
|
async _getXenUpdates () {
|
||||||
const { readAll, statusCode } = await httpRequest(
|
const { readAll, statusCode } = await httpRequest(
|
||||||
'http://updates.xensource.com/XenServer/updates.xml'
|
'http://updates.xensource.com/XenServer/updates.xml',
|
||||||
|
{ agent: httpProxy }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (statusCode !== 200) {
|
if (statusCode !== 200) {
|
||||||
@ -637,7 +642,7 @@ export default class Xapi extends XapiBase {
|
|||||||
throw new Error('no such patch ' + uuid)
|
throw new Error('no such patch ' + uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream = await httpRequest(patchInfo.url)
|
let stream = await httpRequest(patchInfo.url, { agent: httpProxy })
|
||||||
stream = await new Promise((resolve, reject) => {
|
stream = await new Promise((resolve, reject) => {
|
||||||
const PATCH_RE = /\.xsupdate$/
|
const PATCH_RE = /\.xsupdate$/
|
||||||
stream.pipe(unzip.Parse()).on('entry', entry => {
|
stream.pipe(unzip.Parse()).on('entry', entry => {
|
||||||
|
Loading…
Reference in New Issue
Block a user