@@ -6,6 +6,7 @@ var timeoutReq = require('timed-out');
66
77var http = require ( 'http' ) ;
88var https = require ( 'https' ) ;
9+ var Tls = require ( 'tls' ) ;
910
1011function Transport ( ) { }
1112util . inherits ( Transport , events . EventEmitter ) ;
@@ -17,6 +18,7 @@ function HTTPTransport(options) {
1718}
1819util . inherits ( HTTPTransport , Transport ) ;
1920HTTPTransport . prototype . send = function ( client , message , headers , eventId , cb ) {
21+
2022 var options = {
2123 hostname : client . dsn . host ,
2224 path : client . dsn . path + 'api/' + client . dsn . project_id + '/store/' ,
@@ -25,6 +27,17 @@ HTTPTransport.prototype.send = function(client, message, headers, eventId, cb) {
2527 port : client . dsn . port || this . defaultPort ,
2628 ca : client . ca
2729 } ;
30+
31+ // set path apprpriately when using proxy
32+ if ( this . options . hasOwnProperty ( 'host' ) ) {
33+ if ( client . dsn . protocol === 'http' ) {
34+ options . path = 'http://' + client . dsn . host + ':' + client . dsn . port + client . dsn . path + 'api/' + client . dsn . project_id + '/store/'
35+ } else {
36+ options . path = client . dsn . host + ':' + client . dsn . port ;
37+ }
38+ delete options . hostname ; // only 'host' should be set when using proxy
39+ }
40+
2841 for ( var key in this . options ) {
2942 if ( this . options . hasOwnProperty ( key ) ) {
3043 options [ key ] = this . options [ key ] ;
@@ -64,6 +77,22 @@ HTTPTransport.prototype.send = function(client, message, headers, eventId, cb) {
6477 cbFired = true ;
6578 }
6679 } ) ;
80+
81+ // TLS connection for proxying to HTTPS endpoint
82+ /* req.on('connect', function (res, socket, head) {
83+ var cts = Tls.connect({
84+ host: client.dsn.host,
85+ socket: socket
86+ }, function () {
87+ cts.write('GET /welcome HTTP/1.1rnHost: sentry.iornrn');
88+ });
89+
90+ cts.on('data', function (data) {
91+ // console.log(data.toString());
92+ });
93+ });
94+ req.end(); */
95+
6796 req . end ( message ) ;
6897} ;
6998
@@ -72,10 +101,37 @@ function HTTPSTransport(options) {
72101 this . transport = https ;
73102 this . options = options || { } ;
74103}
104+
105+ function HTTPProxyTransport ( options ) {
106+ // this.defaultPort = 80;
107+ this . transport = http ;
108+ this . options = options || { } ;
109+
110+ // set host and port for proxy
111+ this . options . host = options . proxyHost ;
112+ this . options . port = options . proxyPort ;
113+ }
114+
115+ function HTTPSProxyTransport ( options ) {
116+ // Not working yet ):
117+ this . defaultPort = 443 ;
118+ this . transport = http ;
119+ this . options = options || { } ;
120+
121+ this . options . host = options . proxyHost ;
122+ this . options . port = options . proxyPort ;
123+ this . options . method = 'CONNECT' ;
124+ }
125+
75126util . inherits ( HTTPSTransport , HTTPTransport ) ;
127+ util . inherits ( HTTPProxyTransport , HTTPTransport ) ;
128+ util . inherits ( HTTPSProxyTransport , HTTPTransport ) ;
76129
77130module . exports . http = new HTTPTransport ( ) ;
78131module . exports . https = new HTTPSTransport ( ) ;
79132module . exports . Transport = Transport ;
80133module . exports . HTTPTransport = HTTPTransport ;
81134module . exports . HTTPSTransport = HTTPSTransport ;
135+
136+ module . exports . HTTPProxyTransport = HTTPProxyTransport ;
137+ module . exports . HTTPSProxyTransport = HTTPSProxyTransport ;
0 commit comments