@@ -255,25 +255,33 @@ Agent.prototype._evictSession = function _evictSession(key) {
255255
256256const globalAgent = new Agent ( ) ;
257257
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 ) ;
261264 if ( ! options . hostname ) {
262265 throw new ERR_INVALID_DOMAIN_NAME ( ) ;
263266 }
264- } else if ( options && options [ searchParamsSymbol ] &&
265- options [ searchParamsSymbol ] [ searchParamsSymbol ] ) {
267+ } else if ( args [ 0 ] && args [ 0 ] [ searchParamsSymbol ] &&
268+ args [ 0 ] [ searchParamsSymbol ] [ searchParamsSymbol ] ) {
266269 // 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 ( ) ) ;
270275 }
276+
271277 options . _defaultAgent = globalAgent ;
272- return new ClientRequest ( options , cb ) ;
278+ args . unshift ( options ) ;
279+
280+ return new ClientRequest ( ...args ) ;
273281}
274282
275- function get ( options , cb ) {
276- const req = request ( options , cb ) ;
283+ function get ( input , options , cb ) {
284+ const req = request ( input , options , cb ) ;
277285 req . end ( ) ;
278286 return req ;
279287}
0 commit comments