@@ -467,18 +467,8 @@ global.REQUEST = exports.request = function(url, flags, data, callback, cookies,
467467
468468 if ( flags [ i ] [ 0 ] === 'p' && flags [ i ] [ 4 ] === 'y' ) {
469469 // proxy
470- proxy = { } ;
471-
472470 var p = flags [ i ] . substring ( 6 ) ;
473- var index = p . indexOf ( '@' ) ;
474- if ( index !== - 1 ) {
475- // auth
476- var t = p . substring ( 0 , index ) . split ( ':' ) ;
477- p . username = t [ 0 ] ;
478- p . password = t [ 1 ] ;
479- p = p . substring ( index + 1 ) ;
480- }
481-
471+ proxy = { } ;
482472 proxy . protocol = p . substring ( 0 , 7 ) ;
483473 if ( proxy . protocol === 'http://' ) {
484474 proxy . protocol = 'http:' ;
@@ -489,8 +479,16 @@ global.REQUEST = exports.request = function(url, flags, data, callback, cookies,
489479 } else
490480 proxy . protocol = 'http:' ;
491481
492- index = p . lastIndexOf ( ':' ) ;
482+ var index = p . indexOf ( '@' ) ;
483+ if ( index !== - 1 ) {
484+ // auth
485+ var t = p . substring ( 0 , index ) . split ( ':' ) ;
486+ proxy . username = t [ 0 ] ;
487+ proxy . password = t [ 1 ] ;
488+ p = p . substring ( index + 1 ) ;
489+ }
493490
491+ index = p . lastIndexOf ( ':' ) ;
494492 proxy . hostname = p . substring ( 0 , index ) ;
495493 proxy . port = p . substring ( index + 1 ) ;
496494 proxy . method = 'CONNECT' ;
@@ -630,6 +628,9 @@ function request_proxy(options) {
630628 proxy . path = options . uri . hostname ;
631629 proxy . headers = { host : options . uri . hostname } ;
632630
631+ if ( proxy . username && proxy . password )
632+ proxy . headers . authorization = 'Basic ' + U . createBuffer ( proxy . username + ':' + proxy . password ) . toString ( 'base64' ) ;
633+
633634 var req = proxy . protocol === 'http:' ? Http . request ( proxy ) : Https . request ( proxy ) ;
634635
635636 req . on ( 'error' , function ( e ) {
0 commit comments