@@ -109,24 +109,6 @@ describe('HttpsProxyAgent', function () {
109109 assert . equal ( '127.0.0.1' , agent . proxy . host ) ;
110110 assert . equal ( proxyPort , agent . proxy . port ) ;
111111 } ) ;
112- describe ( 'secureEndpoint' , function ( ) {
113- it ( 'should default to `true`' , function ( ) {
114- var agent = new HttpsProxyAgent ( 'http://127.0.0.1:' + proxyPort ) ;
115- assert . equal ( true , agent . secureEndpoint ) ;
116- } ) ;
117- it ( 'should be `false` when passed in as an option' , function ( ) {
118- var opts = url . parse ( 'http://127.0.0.1:' + proxyPort ) ;
119- opts . secureEndpoint = false ;
120- var agent = new HttpsProxyAgent ( opts ) ;
121- assert . equal ( false , agent . secureEndpoint ) ;
122- } ) ;
123- it ( 'should be `true` when passed in as an option' , function ( ) {
124- var opts = url . parse ( 'http://127.0.0.1:' + proxyPort ) ;
125- opts . secureEndpoint = true ;
126- var agent = new HttpsProxyAgent ( opts ) ;
127- assert . equal ( true , agent . secureEndpoint ) ;
128- } ) ;
129- } ) ;
130112 describe ( 'secureProxy' , function ( ) {
131113 it ( 'should default to `false`' , function ( ) {
132114 var agent = new HttpsProxyAgent ( { port : proxyPort } ) ;
@@ -153,6 +135,61 @@ describe('HttpsProxyAgent', function () {
153135 delete proxy . authenticate ;
154136 } ) ;
155137
138+ it ( 'should work over an HTTP proxy' , function ( done ) {
139+ server . once ( 'request' , function ( req , res ) {
140+ res . end ( JSON . stringify ( req . headers ) ) ;
141+ } ) ;
142+
143+ var proxy = process . env . HTTP_PROXY || process . env . http_proxy || 'http://127.0.0.1:' + proxyPort ;
144+ var agent = new HttpsProxyAgent ( proxy ) ;
145+
146+ var opts = url . parse ( 'http://127.0.0.1:' + serverPort ) ;
147+ opts . agent = agent ;
148+
149+ var req = http . get ( opts , function ( res ) {
150+ var data = '' ;
151+ res . setEncoding ( 'utf8' ) ;
152+ res . on ( 'data' , function ( b ) {
153+ data += b ;
154+ } ) ;
155+ res . on ( 'end' , function ( ) {
156+ data = JSON . parse ( data ) ;
157+ assert . equal ( '127.0.0.1:' + serverPort , data . host ) ;
158+ done ( ) ;
159+ } ) ;
160+ } ) ;
161+ req . once ( 'error' , done ) ;
162+ } ) ;
163+ // XXX: doesn't fire the HTTP "response" event for some reason :\
164+ // TODO: look into this some more and fix, even though proxy servers
165+ // over TLS are pretty rare to begin with
166+ it . skip ( 'should work over an HTTPS proxy' , function ( done ) {
167+ sslServer . once ( 'request' , function ( req , res ) {
168+ res . end ( JSON . stringify ( req . headers ) ) ;
169+ } ) ;
170+
171+ var proxy = process . env . HTTPS_PROXY || process . env . https_proxy || 'https://127.0.0.1:' + sslProxyPort ;
172+ proxy = url . parse ( proxy ) ;
173+ proxy . rejectUnauthorized = false ;
174+ var agent = new HttpsProxyAgent ( proxy ) ;
175+
176+ var opts = url . parse ( 'http://127.0.0.1:' + serverPort ) ;
177+ opts . agent = agent ;
178+
179+ http . get ( opts , function ( res ) {
180+ var data = '' ;
181+ res . setEncoding ( 'utf8' ) ;
182+ res . on ( 'data' , function ( b ) {
183+ data += b ;
184+ } ) ;
185+ res . on ( 'end' , function ( ) {
186+ data = JSON . parse ( data ) ;
187+ console . log ( data ) ;
188+ assert . equal ( '127.0.0.1:' + serverPort , data . host ) ;
189+ done ( ) ;
190+ } ) ;
191+ } ) ;
192+ } ) ;
156193 it ( 'should receive the 407 authorization code on the `http.ClientResponse`' , function ( done ) {
157194 // set a proxy authentication function for this test
158195 proxy . authenticate = function ( req , fn ) {
@@ -194,19 +231,11 @@ describe('HttpsProxyAgent', function () {
194231
195232 describe ( '"https" module' , function ( ) {
196233 it ( 'should work over an HTTP proxy' , function ( done ) {
197- // set HTTP "request" event handler for this test
198234 sslServer . once ( 'request' , function ( req , res ) {
199235 res . end ( JSON . stringify ( req . headers ) ) ;
200236 } ) ;
201237
202238 var proxy = process . env . HTTP_PROXY || process . env . http_proxy || 'http://127.0.0.1:' + proxyPort ;
203- proxy = url . parse ( proxy ) ;
204- // `rejectUnauthorized` shoudn't *technically* be necessary here,
205- // but up until node v0.11.6, the `http.Agent` class didn't have
206- // access to the *entire* request "options" object. Thus,
207- // `https-proxy-agent` will *also* merge in options you pass here
208- // to the destination endpoints…
209- proxy . rejectUnauthorized = false ;
210239 var agent = new HttpsProxyAgent ( proxy ) ;
211240
212241 var opts = url . parse ( 'https://127.0.0.1:' + sslServerPort ) ;
@@ -232,15 +261,12 @@ describe('HttpsProxyAgent', function () {
232261 // See: https://github.com/joyent/node/issues/6204
233262
234263 it ( 'should work over an HTTPS proxy' , function ( done ) {
235- // set HTTP "request" event handler for this test
236264 sslServer . once ( 'request' , function ( req , res ) {
237265 res . end ( JSON . stringify ( req . headers ) ) ;
238266 } ) ;
239267
240268 var proxy = process . env . HTTPS_PROXY || process . env . https_proxy || 'https://127.0.0.1:' + sslProxyPort ;
241269 proxy = url . parse ( proxy ) ;
242- // `rejectUnauthorized` is actually necessary this time since the HTTPS
243- // proxy server itself is using a self-signed SSL certificate…
244270 proxy . rejectUnauthorized = false ;
245271 var agent = new HttpsProxyAgent ( proxy ) ;
246272
0 commit comments