@@ -494,7 +494,7 @@ exports.resolve = function(url, callback, param) {
494494 let uri ;
495495
496496 try {
497- uri = new URL ( url ) ;
497+ uri = exports . parseURI ( url ) ;
498498 } catch ( e ) {
499499 callback ( e ) ;
500500 return ;
@@ -546,10 +546,10 @@ function parseProxy(p) {
546546 if ( p . indexOf ( '://' ) === - 1 )
547547 p = 'http://' + p ;
548548
549- const obj = new URL ( p ) ;
549+ const obj = exports . parseURI ( p ) ;
550550
551- if ( obj . username || obj . password )
552- obj . _auth = 'Basic ' + Buffer . from ( obj . username + ':' + obj . password ) . toString ( 'base64' ) ;
551+ if ( obj . auth )
552+ obj . _auth = 'Basic ' + Buffer . from ( obj . auth ) . toString ( 'base64' ) ;
553553
554554 obj . port = + obj . port ;
555555
@@ -691,7 +691,7 @@ function _request(opt, callback) {
691691 }
692692 }
693693
694- const uri = opt . unixsocket ? { socketPath : opt . unixsocket . socket , path : opt . unixsocket . path } : new URL ( opt . url ) ;
694+ const uri = opt . unixsocket ? { socketPath : opt . unixsocket . socket , path : opt . unixsocket . path } : exports . parseURI ( opt . url ) ;
695695
696696 if ( ( opt . unixsocket && ! uri . socketPath ) || ( ! opt . unixsocket && ( ! uri . hostname || ! uri . host ) ) ) {
697697 options . response . canceled = true ;
@@ -770,7 +770,7 @@ exports.request = function(opt, callback) {
770770
771771function request_resolve ( err , uri , options , origin ) {
772772 if ( ! err ) {
773- options . uri . ip = uri . ip ;
773+ options . uri . host = uri . host ;
774774 options . origin = origin ;
775775 }
776776 request_call ( options . uri , options ) ;
@@ -867,8 +867,8 @@ function request_call(uri, options) {
867867 opt . headers = uri . headers ;
868868 opt . method = uri . method ;
869869
870- if ( uri . ip )
871- opt . headers . host = uri . ip ;
870+ if ( uri . host )
871+ opt . headers . host = uri . host ;
872872
873873 if ( options . proxy . _auth )
874874 opt . headers [ 'Proxy-Authorization' ] = options . proxy . _auth ;
@@ -989,11 +989,10 @@ function request_writefile(req, options, file, next) {
989989 return ;
990990 }
991991
992- var filedata = file . buffer || file . url ;
993- var isbuffer = filedata instanceof Buffer ;
994- var isurl = isbuffer ? false : typeof ( filedata ) === 'string' && filedata ;
995-
996- var filename = ( isbuffer || isurl ? file . filename : exports . getName ( file . filename ) ) ;
992+ const filedata = file . buffer || file . url ;
993+ const isbuffer = filedata instanceof Buffer ;
994+ const isurl = isbuffer ? false : typeof ( filedata ) === 'string' && filedata ;
995+ const filename = ( isbuffer || isurl ? file . filename : exports . getName ( file . filename ) ) ;
997996
998997 req . write ( ( options . first ? '' : NEWLINE ) + '--' + options . boundary + NEWLINE + 'Content-Disposition: form-data; name="' + file . name + '"; filename="' + filename + '"' + NEWLINE + 'Content-Type: ' + exports . getContentType ( exports . getExtension ( filename ) ) + NEWLINE + NEWLINE ) ;
999998
@@ -1102,7 +1101,7 @@ function request_response(res) {
11021101 if ( proto !== 'http:/' && proto !== 'https:' )
11031102 loc = uri . protocol + '//' + uri . hostname + ( uri . port && ! SKI_PPORTS [ uri . port ] ? ( ':' + uri . port ) : '' ) + loc ;
11041103
1105- var tmp = new URL ( loc ) ;
1104+ var tmp = exports . parseURI ( loc ) ;
11061105 tmp . headers = uri . headers ;
11071106
11081107 // Transfers cookies
@@ -1123,15 +1122,15 @@ function request_response(res) {
11231122 cookie = cookie . substring ( 0 , index ) ;
11241123 index = cookie . indexOf ( '=' ) ;
11251124 if ( index !== - 1 ) {
1126- var key = decodeURIComponent ( cookie . substring ( 0 , index ) ) ;
1125+ const key = decodeURIComponent ( cookie . substring ( 0 , index ) ) ;
11271126 options . cookies [ key ] = decodeURIComponent ( cookie . substring ( index + 1 ) ) ;
11281127 if ( options . $totalinit . cookies )
11291128 options . $totalinit . cookies [ key ] = options . cookies [ key ] ;
11301129 }
11311130 }
11321131 }
11331132
1134- var builder = '' ;
1133+ let builder = '' ;
11351134 for ( var m in options . cookies )
11361135 builder += ( builder ? '; ' : '' ) + encodeURIComponent ( m ) + '=' + encodeURIComponent ( options . cookies [ m ] ) ;
11371136
@@ -1165,7 +1164,8 @@ function request_response(res) {
11651164 if ( ! options . resolve ) {
11661165 res . removeAllListeners ( ) ;
11671166 res = null ;
1168- return request_call ( tmp , options ) ;
1167+ request_call ( tmp , options ) ;
1168+ return ;
11691169 }
11701170
11711171 exports . resolve ( tmp , function ( err , u , param , origin ) {
@@ -6462,6 +6462,22 @@ exports.uidr = function() {
64626462 return builder + RANDOM_STRING [ sum ] + 'r' ; // "r" version
64636463} ;
64646464
6465+ exports . parseURI = function ( url ) {
6466+ const uri = new URL ( url ) ;
6467+ return {
6468+ auth : ( uri . username || uri . password ) ? ( ( uri . username || '' ) + ':' + ( user . password || '' ) ) : '' ,
6469+ port : uri . port ,
6470+ search : uri . search ,
6471+ hash : uri . hash ,
6472+ pathname : uri . pathname ,
6473+ href : uri . href ,
6474+ protocol : uri . protocol ,
6475+ hostname : uri . hostname ,
6476+ host : uri . host ,
6477+ path : uri . pathname + uri . search
6478+ } ;
6479+ } ;
6480+
64656481exports . paginate = function ( page , pages , max ) {
64666482
64676483 if ( ! page )
0 commit comments