@@ -1136,27 +1136,32 @@ function domainToUnicode(domain) {
11361136 return _domainToUnicode ( `${ domain } ` ) ;
11371137}
11381138
1139- // Utility function that converts a URL object into an ordinary
1140- // options object as expected by the http.request and https.request
1141- // APIs.
1139+ /**
1140+ * Utility function that converts a URL object into an ordinary options object
1141+ * as expected by the `http.request` and `https.request` APIs.
1142+ * @param {URL } url
1143+ * @returns {Record<string, unknown> }
1144+ */
11421145function urlToHttpOptions ( url ) {
1146+ const { hostname, pathname, port, username, password, search } = url ;
11431147 const options = {
1148+ __proto__ : null ,
1149+ ...url , // In case the url object was extended by the user.
11441150 protocol : url . protocol ,
1145- hostname : typeof url . hostname === 'string' &&
1146- StringPrototypeStartsWith ( url . hostname , '[' ) ?
1147- StringPrototypeSlice ( url . hostname , 1 , - 1 ) :
1148- url . hostname ,
1151+ hostname : typeof url . hostname === 'string' && StringPrototypeStartsWith ( hostname , '[' ) ?
1152+ StringPrototypeSlice ( hostname , 1 , - 1 ) :
1153+ hostname ,
11491154 hash : url . hash ,
1150- search : url . search ,
1151- pathname : url . pathname ,
1152- path : `${ url . pathname || '' } ${ url . search || '' } ` ,
1155+ search : search ,
1156+ pathname : pathname ,
1157+ path : `${ pathname || '' } ${ search || '' } ` ,
11531158 href : url . href ,
11541159 } ;
1155- if ( url . port !== '' ) {
1156- options . port = Number ( url . port ) ;
1160+ if ( port !== '' ) {
1161+ options . port = Number ( port ) ;
11571162 }
1158- if ( url . username || url . password ) {
1159- options . auth = `${ decodeURIComponent ( url . username ) } :${ decodeURIComponent ( url . password ) } ` ;
1163+ if ( username || password ) {
1164+ options . auth = `${ decodeURIComponent ( username ) } :${ decodeURIComponent ( password ) } ` ;
11601165 }
11611166 return options ;
11621167}
0 commit comments