diff --git a/index.d.ts b/index.d.ts index 331b8f2d..38e0d220 100644 --- a/index.d.ts +++ b/index.d.ts @@ -61,7 +61,7 @@ export interface ProviderOptions { /** * Connect through an HTTP proxy */ - proxy?: { host: string, port: number|string } + proxy?: { host: string, port: number|string, user?: string, pass?: string } } export interface MultiProviderOptions extends ProviderOptions { @@ -154,7 +154,7 @@ export class MultiProvider extends EventEmitter { * Set an info logger, and optionally an errorLogger to separately log errors. * * In order to log, these functions must have a property '.enabled' that is true. - * (The default logger uses the npm 'debug' module which sets '.enabled' + * (The default logger uses the npm 'debug' module which sets '.enabled' * based on the DEBUG environment variable) */ setLogger(logger: (msg: string) => void, errorLogger?: (msg: string) => void): Promise; diff --git a/lib/util/proxy.js b/lib/util/proxy.js index f91e3b0a..82fead1d 100644 --- a/lib/util/proxy.js +++ b/lib/util/proxy.js @@ -2,12 +2,18 @@ const http = require('http'); module.exports = function createProxySocket(proxy, target) { return new Promise((resolve, reject) => { + let headers = { Connection: "Keep-Alive" }; + if (proxy.user && proxy.pass) { + const token = Buffer.from(`${proxy.user}:${proxy.pass}`).toString('base64') + headers["Proxy-Authorization"] = `Basic ${token}` + } + const req = http.request({ host: proxy.host, port: proxy.port, - method: 'connect', - path: target.host + ':' + target.port, - headers: { Connection: 'Keep-Alive' }, + method: "connect", + path: target.host + ":" + target.port, + headers: headers, }); req.on('error', reject); req.on('connect', (res, socket, head) => {