@@ -262,6 +262,7 @@ public function request(string $method, string $url, array $options = []): Respo
262
262
$ context = stream_context_create ($ context , ['notification ' => $ notification ]);
263
263
264
264
$ resolver = static function ($ multi ) use ($ context , $ options , $ url , &$ info , $ onProgress ) {
265
+ $ authority = $ url ['authority ' ];
265
266
[$ host , $ port ] = self ::parseHostPort ($ url , $ info );
266
267
267
268
if (!isset ($ options ['normalized_headers ' ]['host ' ])) {
@@ -275,7 +276,7 @@ public function request(string $method, string $url, array $options = []): Respo
275
276
$ url ['authority ' ] = substr_replace ($ url ['authority ' ], $ ip , -\strlen ($ host ) - \strlen ($ port ), \strlen ($ host ));
276
277
}
277
278
278
- return [self ::createRedirectResolver ($ options , $ host , $ port , $ proxy , $ info , $ onProgress ), implode ('' , $ url )];
279
+ return [self ::createRedirectResolver ($ options , $ authority , $ proxy , $ info , $ onProgress ), implode ('' , $ url )];
279
280
};
280
281
281
282
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
373
374
/**
374
375
* Handles redirects - the native logic is too buggy to be used.
375
376
*/
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
377
378
{
378
379
$ redirectHeaders = [];
379
380
if (0 < $ maxRedirects = $ options ['max_redirects ' ]) {
380
- $ redirectHeaders = ['host ' => $ host , ' port ' => $ port ];
381
+ $ redirectHeaders = ['authority ' => $ authority ];
381
382
$ redirectHeaders ['with_auth ' ] = $ redirectHeaders ['no_auth ' ] = array_filter ($ options ['headers ' ], static fn ($ h ) => 0 !== stripos ($ h , 'Host: ' ));
382
383
383
384
if (isset ($ options ['normalized_headers ' ]['authorization ' ]) || isset ($ options ['normalized_headers ' ]['cookie ' ])) {
@@ -435,8 +436,8 @@ private static function createRedirectResolver(array $options, string $host, str
435
436
[$ host , $ port ] = self ::parseHostPort ($ url , $ info );
436
437
437
438
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 ' ];
440
441
$ requestHeaders [] = 'Host: ' .$ host .$ port ;
441
442
$ dnsResolve = !self ::configureHeadersAndProxy ($ context , $ host , $ requestHeaders , $ proxy , 'https: ' === $ url ['scheme ' ]);
442
443
} else {
0 commit comments