@@ -1098,26 +1098,32 @@ function domainToUnicode(domain) {
1098
1098
return _domainToUnicode ( `${ domain } ` ) ;
1099
1099
}
1100
1100
1101
- // Utility function that converts a URL object into an ordinary
1102
- // options object as expected by the http.request and https.request
1103
- // APIs.
1101
+ /**
1102
+ * Utility function that converts a URL object into an ordinary options object
1103
+ * as expected by the `http.request` and `https.request` APIs.
1104
+ * @param {URL } url
1105
+ * @returns {Record<string, unknown> }
1106
+ */
1104
1107
function urlToHttpOptions ( url ) {
1108
+ const { hostname, pathname, port, username, password, search } = url ;
1105
1109
const options = {
1110
+ __proto__ : null ,
1111
+ ...url , // In case the url object was extended by the user.
1106
1112
protocol : url . protocol ,
1107
- hostname : url . hostname && StringPrototypeStartsWith ( url . hostname , '[' ) ?
1108
- StringPrototypeSlice ( url . hostname , 1 , - 1 ) :
1109
- url . hostname ,
1113
+ hostname : hostname && StringPrototypeStartsWith ( hostname , '[' ) ?
1114
+ StringPrototypeSlice ( hostname , 1 , - 1 ) :
1115
+ hostname ,
1110
1116
hash : url . hash ,
1111
- search : url . search ,
1112
- pathname : url . pathname ,
1113
- path : `${ url . pathname || '' } ${ url . search || '' } ` ,
1117
+ search : search ,
1118
+ pathname : pathname ,
1119
+ path : `${ pathname || '' } ${ search || '' } ` ,
1114
1120
href : url . href ,
1115
1121
} ;
1116
- if ( url . port !== '' ) {
1117
- options . port = Number ( url . port ) ;
1122
+ if ( port !== '' ) {
1123
+ options . port = Number ( port ) ;
1118
1124
}
1119
- if ( url . username || url . password ) {
1120
- options . auth = `${ decodeURIComponent ( url . username ) } :${ decodeURIComponent ( url . password ) } ` ;
1125
+ if ( username || password ) {
1126
+ options . auth = `${ decodeURIComponent ( username ) } :${ decodeURIComponent ( password ) } ` ;
1121
1127
}
1122
1128
return options ;
1123
1129
}
0 commit comments