@@ -28,6 +28,7 @@ const {
2828 NumberIsFinite,
2929 ObjectAssign,
3030 ObjectDefineProperty,
31+ ObjectHasOwn,
3132 ObjectKeys,
3233 ObjectSetPrototypeOf,
3334 ReflectApply,
@@ -331,12 +332,15 @@ function rewriteForProxiedHttp(req, reqOptions, proxyAuthority, userHostHeader,
331332function ClientRequest ( input , options , cb ) {
332333 OutgoingMessage . call ( this ) ;
333334
335+ let pathIsFromURL = false ;
334336 if ( typeof input === 'string' ) {
335337 const urlStr = input ;
336338 input = urlToHttpOptions ( new URL ( urlStr ) ) ;
339+ pathIsFromURL = true ;
337340 } else if ( isURL ( input ) ) {
338341 // url.URL instance
339342 input = urlToHttpOptions ( input ) ;
343+ pathIsFromURL = true ;
340344 } else {
341345 cb = options ;
342346 options = input ;
@@ -347,6 +351,13 @@ function ClientRequest(input, options, cb) {
347351 cb = options ;
348352 options = input || kEmptyObject ;
349353 } else {
354+ const hasPathOverride = pathIsFromURL &&
355+ options != null &&
356+ ObjectHasOwn ( options , 'path' ) ;
357+ if ( hasPathOverride ) {
358+ pathIsFromURL = false ;
359+ }
360+
350361 options = ObjectAssign ( { __proto__ : null } , input , options ) ;
351362 }
352363
@@ -466,7 +477,13 @@ function ClientRequest(input, options, cb) {
466477
467478 this . joinDuplicateHeaders = options . joinDuplicateHeaders ;
468479
469- this [ kPath ] = options . path || '/' ;
480+ let path = options . path || '/' ;
481+ // Strip the leading slash added when the CONNECT target comes from a URL.
482+ if ( method === 'CONNECT' && pathIsFromURL && path [ 0 ] === '/' ) {
483+ path = path . slice ( 1 ) || '/' ;
484+ }
485+
486+ this [ kPath ] = path ;
470487 if ( cb ) {
471488 this . once ( 'response' , cb ) ;
472489 }
0 commit comments