Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for HTTP-Proxy-Authorization #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Responses>;
Expand Down
12 changes: 9 additions & 3 deletions lib/util/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down