Merge pull request #237 from vatesfr/http-proxy

HTTP proxy support (fix vatesfr/xo-web#737).
This commit is contained in:
Julien Fontanet 2016-02-16 15:57:29 +01:00
commit 558956bf55
5 changed files with 35 additions and 4 deletions

View File

@ -111,6 +111,7 @@
"passport": "^0.3.0",
"passport-local": "^1.0.0",
"promise-toolbox": "^0.1.0",
"proxy-agent": "^2.0.0",
"proxy-http-request": "0.1.0",
"redis": "^2.0.1",
"schema-inspector": "^1.5.1",

View File

@ -107,6 +107,12 @@ http:
proxies:
# '/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.

12
src/http-proxy.js Normal file
View 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)

View File

@ -37,6 +37,9 @@ import Api from './api'
import WebServer from 'http-server-plus'
import wsProxy from './ws-proxy'
import Xo from './xo'
import {
setup as setupHttpProxy
} from './http-proxy'
import {
createRawObject,
forEach,
@ -600,6 +603,10 @@ export default async function main (args) {
warn('Failed to change user/group:', error)
}
if (config.httpProxy) {
setupHttpProxy(config.httpProxy)
}
// Creates main object.
const xo = new Xo(config)

View File

@ -17,14 +17,18 @@ import {
wrapError as wrapXapiError,
Xapi as XapiBase
} from 'xen-api'
import {
satisfies as versionSatisfies
} from 'semver'
import httpRequest from './http-request'
import {
debounce,
deferrable
} from './decorators'
import { satisfies as versionSatisfies } from 'semver'
import {
agent as httpProxy
} from './http-proxy'
import {
bufferToStream,
camelToSnakeCase,
@ -447,7 +451,8 @@ export default class Xapi extends XapiBase {
@debounce(24 * 60 * 60 * 1000)
async _getXenUpdates () {
const { readAll, statusCode } = await httpRequest(
'http://updates.xensource.com/XenServer/updates.xml'
'http://updates.xensource.com/XenServer/updates.xml',
{ agent: httpProxy }
)
if (statusCode !== 200) {
@ -637,7 +642,7 @@ export default class Xapi extends XapiBase {
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) => {
const PATCH_RE = /\.xsupdate$/
stream.pipe(unzip.Parse()).on('entry', entry => {