@@ -375,18 +375,22 @@ function ClientRequest(input, options, cb) {
375375 if ( host && ! this . getHeader ( 'host' ) && setHost ) {
376376 let hostHeader = host ;
377377
378- // For the Host header, ensure that IPv6 addresses are enclosed
379- // in square brackets, as defined by URI formatting
380- // https://tools.ietf.org/html/rfc3986#section-3.2.2
381- const posColon = hostHeader . indexOf ( ':' ) ;
382- if ( posColon !== - 1 &&
383- hostHeader . includes ( ':' , posColon + 1 ) &&
384- hostHeader . charCodeAt ( 0 ) !== 91 /* '[' */ ) {
385- hostHeader = `[${ hostHeader } ]` ;
386- }
378+ if ( method === 'CONNECT' && options . path ) {
379+ hostHeader = String ( this . path ) ;
380+ } else {
381+ // For the Host header, ensure that IPv6 addresses are enclosed
382+ // in square brackets, as defined by URI formatting
383+ // https://tools.ietf.org/html/rfc3986#section-3.2.2
384+ const posColon = hostHeader . indexOf ( ':' ) ;
385+ if ( posColon !== - 1 &&
386+ hostHeader . includes ( ':' , posColon + 1 ) &&
387+ hostHeader . charCodeAt ( 0 ) !== 91 /* '[' */ ) {
388+ hostHeader = `[${ hostHeader } ]` ;
389+ }
387390
388- if ( port && + port !== defaultPort ) {
389- hostHeader += ':' + port ;
391+ if ( port && + port !== defaultPort ) {
392+ hostHeader += ':' + port ;
393+ }
390394 }
391395 this . setHeader ( 'Host' , hostHeader ) ;
392396 }
0 commit comments