@@ -255,25 +255,33 @@ Agent.prototype._evictSession = function _evictSession(key) {
255
255
256
256
const globalAgent = new Agent ( ) ;
257
257
258
- function request ( options , cb ) {
259
- if ( typeof options === 'string' ) {
260
- options = url . parse ( options ) ;
258
+ function request ( ...args ) {
259
+ let options = { } ;
260
+
261
+ if ( typeof args [ 0 ] === 'string' ) {
262
+ const urlStr = args . shift ( ) ;
263
+ options = url . parse ( urlStr ) ;
261
264
if ( ! options . hostname ) {
262
265
throw new ERR_INVALID_DOMAIN_NAME ( ) ;
263
266
}
264
- } else if ( options && options [ searchParamsSymbol ] &&
265
- options [ searchParamsSymbol ] [ searchParamsSymbol ] ) {
267
+ } else if ( args [ 0 ] && args [ 0 ] [ searchParamsSymbol ] &&
268
+ args [ 0 ] [ searchParamsSymbol ] [ searchParamsSymbol ] ) {
266
269
// url.URL instance
267
- options = urlToOptions ( options ) ;
268
- } else {
269
- options = util . _extend ( { } , options ) ;
270
+ options = urlToOptions ( args . shift ( ) ) ;
271
+ }
272
+
273
+ if ( args [ 0 ] && typeof args [ 0 ] !== 'function' ) {
274
+ options = util . _extend ( options , args . shift ( ) ) ;
270
275
}
276
+
271
277
options . _defaultAgent = globalAgent ;
272
- return new ClientRequest ( options , cb ) ;
278
+ args . unshift ( options ) ;
279
+
280
+ return new ClientRequest ( ...args ) ;
273
281
}
274
282
275
- function get ( options , cb ) {
276
- const req = request ( options , cb ) ;
283
+ function get ( input , options , cb ) {
284
+ const req = request ( input , options , cb ) ;
277
285
req . end ( ) ;
278
286
return req ;
279
287
}
0 commit comments