Skip to content

Commit

Permalink
[HttpClient] fix bufferRegex declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
rjwebdev committed Jul 25, 2019
1 parent 553a9be commit 7b33c42
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/Symfony/Component/HttpClient/HttpClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ private static function prepareRequest(?string $method, ?string $url, array $opt

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

if (isset($options['json'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpClient/Response/CurlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
rewind($content);
$multi->handlesActivity[$id][] = stream_get_contents($content);
}
$content = isset($options['buffer']) && true === $options['buffer'] ? $content : null;
$content = ($options['buffer'] ?? true) && !\is_string($options['buffer'] ?? true) ? $content : null;
}

curl_setopt($ch, CURLOPT_HEADERFUNCTION, static function ($ch, string $data) use (&$info, &$headers, $options, $multi, $id, &$location, $resolveRedirect, $logger, &$content): int {
Expand Down Expand Up @@ -345,7 +345,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
return 0;
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpClient/Response/NativeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(NativeClientState $multi, $context, string $url, $op
$this->resolveRedirect = $resolveRedirect;
$this->onProgress = $onProgress;
$this->content = ($options['buffer'] ?? true) && !\is_string($options['buffer'] ?? true) ? fopen('php://temp', 'w+') : null;
$this->bufferRegex = \is_string($options['buffer'] ?? null);
$this->bufferRegex = \is_string($options['buffer'] ?? null) ? $options['buffer'] : null;

// Temporary resources to dechunk/inflate the response stream
$this->buffer = fopen('php://temp', 'w+');
Expand Down Expand Up @@ -154,7 +154,7 @@ private function open(): void
stream_set_blocking($h, false);
$this->context = $this->resolveRedirect = null;

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

Expand Down

0 comments on commit 7b33c42

Please sign in to comment.