|
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 | /**
|
@@ -103,31 +102,33 @@ public function request(string $method, string $url, array $options = []): Respo
|
103 | 102 | $ip = self::dnsResolve($dnsCache, $host, $this->ipFlags, $options);
|
104 | 103 | self::ipCheck($ip, $this->subnets, $this->ipFlags, $host, $url);
|
105 | 104 |
|
106 |
| - if (0 < $maxRedirects = $options['max_redirects']) { |
107 |
| - $options['max_redirects'] = 0; |
108 |
| - $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = $options['headers']; |
109 |
| - |
110 |
| - if (isset($options['normalized_headers']['host']) || isset($options['normalized_headers']['authorization']) || isset($options['normalized_headers']['cookie'])) { |
111 |
| - $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], static function ($h) { |
112 |
| - return 0 !== stripos($h, 'Host:') && 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:'); |
113 |
| - }); |
114 |
| - } |
115 |
| - } |
116 |
| - |
117 | 105 | $onProgress = $options['on_progress'] ?? null;
|
118 | 106 | $subnets = $this->subnets;
|
119 | 107 | $ipFlags = $this->ipFlags;
|
120 | 108 | $lastPrimaryIp = '';
|
121 | 109 |
|
122 | 110 | $options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use ($onProgress, $subnets, $ipFlags, &$lastPrimaryIp): void {
|
123 |
| - if (($info['primary_ip'] ?? '') !== $lastPrimaryIp) { |
| 111 | + if (!\in_array($info['primary_ip'] ?? '', ['', $lastPrimaryIp], true)) { |
124 | 112 | self::ipCheck($info['primary_ip'], $subnets, $ipFlags, null, $info['url']);
|
125 | 113 | $lastPrimaryIp = $info['primary_ip'];
|
126 | 114 | }
|
127 | 115 |
|
128 | 116 | null !== $onProgress && $onProgress($dlNow, $dlSize, $info);
|
129 | 117 | };
|
130 | 118 |
|
| 119 | + if (0 >= $maxRedirects = $options['max_redirects']) { |
| 120 | + return new AsyncResponse($this->client, $method, $url, $options); |
| 121 | + } |
| 122 | + |
| 123 | + $options['max_redirects'] = 0; |
| 124 | + $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = $options['headers']; |
| 125 | + |
| 126 | + if (isset($options['normalized_headers']['host']) || isset($options['normalized_headers']['authorization']) || isset($options['normalized_headers']['cookie'])) { |
| 127 | + $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], static function ($h) { |
| 128 | + return 0 !== stripos($h, 'Host:') && 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:'); |
| 129 | + }); |
| 130 | + } |
| 131 | + |
131 | 132 | return new AsyncResponse($this->client, $method, $url, $options, static function (ChunkInterface $chunk, AsyncContext $context) use (&$method, &$options, $maxRedirects, &$redirectHeaders, $subnets, $ipFlags, $dnsCache): \Generator {
|
132 | 133 | if (null !== $chunk->getError() || $chunk->isTimeout() || !$chunk->isFirst()) {
|
133 | 134 | yield $chunk;
|
@@ -178,14 +179,6 @@ public function request(string $method, string $url, array $options = []): Respo
|
178 | 179 | });
|
179 | 180 | }
|
180 | 181 |
|
181 |
| - /** |
182 |
| - * {@inheritdoc} |
183 |
| - */ |
184 |
| - public function stream($responses, ?float $timeout = null): ResponseStreamInterface |
185 |
| - { |
186 |
| - return $this->client->stream($responses, $timeout); |
187 |
| - } |
188 |
| - |
189 | 182 | /**
|
190 | 183 | * {@inheritdoc}
|
191 | 184 | */
|
|
0 commit comments