@@ -1136,27 +1136,32 @@ function domainToUnicode(domain) {
1136
1136
return _domainToUnicode ( `${ domain } ` ) ;
1137
1137
}
1138
1138
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
+ */
1142
1145
function urlToHttpOptions ( url ) {
1146
+ const { hostname, pathname, port, username, password, search } = url ;
1143
1147
const options = {
1148
+ __proto__ : null ,
1149
+ ...url , // In case the url object was extended by the user.
1144
1150
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 ,
1149
1154
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 || '' } ` ,
1153
1158
href : url . href ,
1154
1159
} ;
1155
- if ( url . port !== '' ) {
1156
- options . port = Number ( url . port ) ;
1160
+ if ( port !== '' ) {
1161
+ options . port = Number ( port ) ;
1157
1162
}
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 ) } ` ;
1160
1165
}
1161
1166
return options ;
1162
1167
}
0 commit comments