Skip to content

Commit 66c4079

Browse files
committed
[HttpClient] change content and regex checks
1 parent bf1ab0c commit 66c4079

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
4444

4545
if (\is_string($options['buffer'] ?? null) && false === @preg_match($options['buffer'], '')) {
4646
throw new InvalidArgumentException('Option "buffer" should be a valid regular expression.');
47+
// try {
48+
// preg_match($options['buffer'], '');
49+
// } catch (\Exception $exception) {
50+
// }
4751
}
4852

4953
if (isset($options['json'])) {

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
345345
return 0;
346346
}
347347

348-
if (isset($headers['content-type'], $options['buffer']) && \is_string($options['buffer'])) {
348+
if (isset($headers['content-type'], $options['buffer']) && \is_string($options['buffer'] ?? null) && null === $content) {
349349
$content = self::createBufferForContentType($headers['content-type'][0], $options['buffer']);
350350
}
351351

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private function open(): void
154154
stream_set_blocking($h, false);
155155
$this->context = $this->resolveRedirect = null;
156156

157-
if (null !== $this->bufferRegex && isset($this->headers['content-type'])) {
157+
if ($this->bufferRegex && isset($this->headers['content-type']) && null === $this->content) {
158158
$this->content = self::createBufferForContentType($this->headers['content-type'][0], $this->bufferRegex);
159159
}
160160

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\HttpClient\Tests;
1313

14+
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1415
use Symfony\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
1516

1617
abstract class HttpClientTestCase extends BaseHttpClientTestCase
@@ -37,19 +38,18 @@ public function testJsonRegexBuffer(): void
3738
{
3839
$client = $this->getHttpClient(__FUNCTION__);
3940
$response = $client->request('GET', 'http://localhost:8057', ['buffer' => '/([a-z]+\/json)/']);
40-
4141
$firstContent = $response->getContent();
4242
$secondContent = $response->getContent();
4343

4444
$this->assertSame($firstContent, $secondContent);
4545
}
4646

47-
/**
48-
* @expectedException \Symfony\Component\HttpClient\Exception\InvalidArgumentException
49-
*/
5047
public function testInvalidRegexBuffer(): void
5148
{
5249
$client = $this->getHttpClient(__FUNCTION__);
50+
51+
$this->expectException(InvalidArgumentException::class);
52+
5353
$response = $client->request('GET', 'http://localhost:8057', ['buffer' => '/([a-z]+\/json))/']);
5454

5555
$firstPosts = $response->getContent();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy