Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit de6da9e

Browse files
committed
Add proxyAuth (ability to specify user/password for proxy)
1 parent 6cce30b commit de6da9e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/transports.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var timeoutReq = require('timed-out');
77
var http = require('http');
88
var https = require('https');
99
var tunnel = require('tunnel-agent');
10+
var Buffer = require("safe-buffer").Buffer;
1011

1112
var agentOptions = {
1213
keepAlive: true,
@@ -41,6 +42,11 @@ HTTPTransport.prototype.send = function (client, message, headers, eventId, cb)
4142
if (client.dsn.protocol === 'http') {
4243
options.path = 'http://' + client.dsn.host + ':' + client.dsn.port + client.dsn.path + 'api/' + client.dsn.project_id + '/store/';
4344
delete options.hostname; // only 'host' should be set when using proxy
45+
46+
if (this.options.proxyAuth) {
47+
// might be able to use httpOverHttp agent
48+
options.headers["Proxy-Authorization"] = "Basic " + Buffer.from(this.options.proxyAuth).toString("base64");
49+
}
4450
} else {
4551
this.options.agent.proxyOptions.headers = {
4652
'Content-Type': 'application/octet-stream',
@@ -117,6 +123,10 @@ function HTTPProxyTransport(options) {
117123
this.agent = httpAgent;
118124
this.options.host = options.proxyHost;
119125
this.options.port = options.proxyPort;
126+
127+
if (options.proxyUser && options.proxyPassword) {
128+
this.options.proxyAuth = options.proxyUser + ':' + options.proxyPassword;
129+
}
120130
}
121131

122132
function HTTPSProxyTransport(options) {
@@ -127,7 +137,10 @@ function HTTPSProxyTransport(options) {
127137
proxy: {
128138
host: options.proxyHost,
129139
port: options.proxyPort,
130-
proxyAuth: null // TODO: Add ability to specify creds/auth
140+
proxyAuth:
141+
options.proxyUser && options.proxyPassword
142+
? options.proxyUser + ':' + options.proxyPassword
143+
: null
131144
},
132145
keepAlive: agentOptions.keepAlive,
133146
maxSockets: agentOptions.maxSockets

0 commit comments

Comments
 (0)