@@ -262,6 +262,7 @@ public function request(string $method, string $url, array $options = []): Respo
262262 $ context = stream_context_create ($ context , ['notification ' => $ notification ]);
263263
264264 $ resolver = static function ($ multi ) use ($ context , $ options , $ url , &$ info , $ onProgress ) {
265+ $ authority = $ url ['authority ' ];
265266 [$ host , $ port ] = self ::parseHostPort ($ url , $ info );
266267
267268 if (!isset ($ options ['normalized_headers ' ]['host ' ])) {
@@ -275,7 +276,7 @@ public function request(string $method, string $url, array $options = []): Respo
275276 $ url ['authority ' ] = substr_replace ($ url ['authority ' ], $ ip , -\strlen ($ host ) - \strlen ($ port ), \strlen ($ host ));
276277 }
277278
278- return [self ::createRedirectResolver ($ options , $ host , $ port , $ proxy , $ info , $ onProgress ), implode ('' , $ url )];
279+ return [self ::createRedirectResolver ($ options , $ authority , $ proxy , $ info , $ onProgress ), implode ('' , $ url )];
279280 };
280281
281282 return new NativeResponse ($ this ->multi , $ context , implode ('' , $ url ), $ options , $ info , $ resolver , $ onProgress , $ this ->logger );
@@ -373,11 +374,11 @@ private static function dnsResolve(string $host, NativeClientState $multi, array
373374 /**
374375 * Handles redirects - the native logic is too buggy to be used.
375376 */
376- private static function createRedirectResolver (array $ options , string $ host , string $ port , ?array $ proxy , array &$ info , ?\Closure $ onProgress ): \Closure
377+ private static function createRedirectResolver (array $ options , string $ authority , ?array $ proxy , array &$ info , ?\Closure $ onProgress ): \Closure
377378 {
378379 $ redirectHeaders = [];
379380 if (0 < $ maxRedirects = $ options ['max_redirects ' ]) {
380- $ redirectHeaders = ['host ' => $ host , ' port ' => $ port ];
381+ $ redirectHeaders = ['authority ' => $ authority ];
381382 $ redirectHeaders ['with_auth ' ] = $ redirectHeaders ['no_auth ' ] = array_filter ($ options ['headers ' ], static fn ($ h ) => 0 !== stripos ($ h , 'Host: ' ));
382383
383384 if (isset ($ options ['normalized_headers ' ]['authorization ' ]) || isset ($ options ['normalized_headers ' ]['cookie ' ])) {
@@ -435,8 +436,8 @@ private static function createRedirectResolver(array $options, string $host, str
435436 [$ host , $ port ] = self ::parseHostPort ($ url , $ info );
436437
437438 if ($ locationHasHost ) {
438- // Authorization and Cookie headers MUST NOT follow except for the initial host name
439- $ requestHeaders = $ redirectHeaders ['host ' ] === $ host && $ redirectHeaders [ ' port ' ] === $ port ? $ redirectHeaders ['with_auth ' ] : $ redirectHeaders ['no_auth ' ];
439+ // Authorization and Cookie headers MUST NOT follow except for the initial authority name
440+ $ requestHeaders = $ redirectHeaders ['authority ' ] === $ url [ ' authority ' ] ? $ redirectHeaders ['with_auth ' ] : $ redirectHeaders ['no_auth ' ];
440441 $ requestHeaders [] = 'Host: ' .$ host .$ port ;
441442 $ dnsResolve = !self ::configureHeadersAndProxy ($ context , $ host , $ requestHeaders , $ proxy , 'https: ' === $ url ['scheme ' ]);
442443 } else {
0 commit comments