|
20 | 20 | use Symfony\Contracts\HttpClient\ChunkInterface;
|
21 | 21 | use Symfony\Contracts\HttpClient\HttpClientInterface;
|
22 | 22 | use Symfony\Contracts\HttpClient\ResponseInterface;
|
23 |
| -use Symfony\Contracts\HttpClient\ResponseStreamInterface; |
24 | 23 | use Symfony\Contracts\Service\ResetInterface;
|
25 | 24 |
|
26 | 25 | /**
|
@@ -81,32 +80,34 @@ public function request(string $method, string $url, array $options = []): Respo
|
81 | 80 | $ip = self::dnsResolve($dnsCache, $host, $this->ipFlags, $options);
|
82 | 81 | self::ipCheck($ip, $this->subnets, $this->ipFlags, $host, $url);
|
83 | 82 |
|
84 |
| - if (0 < $maxRedirects = $options['max_redirects']) { |
85 |
| - $options['max_redirects'] = 0; |
86 |
| - $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = $options['headers']; |
87 |
| - |
88 |
| - if (isset($options['normalized_headers']['host']) || isset($options['normalized_headers']['authorization']) || isset($options['normalized_headers']['cookie'])) { |
89 |
| - $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], static function ($h) { |
90 |
| - return 0 !== stripos($h, 'Host:') && 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:'); |
91 |
| - }); |
92 |
| - } |
93 |
| - } |
94 |
| - |
95 | 83 | $onProgress = $options['on_progress'] ?? null;
|
96 | 84 | $subnets = $this->subnets;
|
97 | 85 | $ipFlags = $this->ipFlags;
|
98 | 86 |
|
99 | 87 | $options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use ($onProgress, $subnets, $ipFlags): void {
|
100 | 88 | static $lastPrimaryIp = '';
|
101 | 89 |
|
102 |
| - if (($info['primary_ip'] ?? '') !== $lastPrimaryIp) { |
| 90 | + if (!\in_array($info['primary_ip'] ?? '', ['', $lastPrimaryIp], true)) { |
103 | 91 | self::ipCheck($info['primary_ip'], $subnets, $ipFlags, null, $info['url']);
|
104 | 92 | $lastPrimaryIp = $info['primary_ip'];
|
105 | 93 | }
|
106 | 94 |
|
107 | 95 | null !== $onProgress && $onProgress($dlNow, $dlSize, $info);
|
108 | 96 | };
|
109 | 97 |
|
| 98 | + if (0 >= $maxRedirects = $options['max_redirects']) { |
| 99 | + return new AsyncResponse($this->client, $method, $url, $options); |
| 100 | + } |
| 101 | + |
| 102 | + $options['max_redirects'] = 0; |
| 103 | + $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = $options['headers']; |
| 104 | + |
| 105 | + if (isset($options['normalized_headers']['host']) || isset($options['normalized_headers']['authorization']) || isset($options['normalized_headers']['cookie'])) { |
| 106 | + $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], static function ($h) { |
| 107 | + return 0 !== stripos($h, 'Host:') && 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:'); |
| 108 | + }); |
| 109 | + } |
| 110 | + |
110 | 111 | return new AsyncResponse($this->client, $method, $url, $options, static function (ChunkInterface $chunk, AsyncContext $context) use (&$method, &$options, $maxRedirects, &$redirectHeaders, $subnets, $ipFlags, $dnsCache): \Generator {
|
111 | 112 | if (null !== $chunk->getError() || $chunk->isTimeout() || !$chunk->isFirst()) {
|
112 | 113 | yield $chunk;
|
@@ -158,11 +159,6 @@ public function request(string $method, string $url, array $options = []): Respo
|
158 | 159 | });
|
159 | 160 | }
|
160 | 161 |
|
161 |
| - public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface |
162 |
| - { |
163 |
| - return $this->client->stream($responses, $timeout); |
164 |
| - } |
165 |
| - |
166 | 162 | /**
|
167 | 163 | * @deprecated since Symfony 7.1, configure the logger on the wrapped HTTP client directly instead
|
168 | 164 | */
|
|
0 commit comments