Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 81b50b5

Browse filesBrowse files
[HttpClient] fix casting responses to PHP streams
1 parent 47f7cdc commit 81b50b5
Copy full SHA for 81b50b5

File tree

4 files changed

+21
-12
lines changed
Filter options

4 files changed

+21
-12
lines changed

‎src/Symfony/Component/HttpClient/CurlHttpClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/CurlHttpClient.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function request(string $method, string $url, array $options = []): Respo
288288
$pushedResponse = $pushedResponse->response;
289289
$pushedResponse->__construct($this->multi, $url, $options, $this->logger);
290290
} else {
291-
$this->logger && $this->logger->debug(sprintf('Rejecting pushed response: "%s".', $url));
291+
$this->logger && $this->logger->debug(sprintf('Rejecting pushed response: "%s"', $url));
292292
$pushedResponse = null;
293293
}
294294
}

‎src/Symfony/Component/HttpClient/NativeHttpClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/NativeHttpClient.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function request(string $method, string $url, array $options = []): Respo
169169
$this->multi->dnsCache = $options['resolve'] + $this->multi->dnsCache;
170170
}
171171

172-
$this->logger && $this->logger->info(sprintf('Request: %s %s', $method, implode('', $url)));
172+
$this->logger && $this->logger->info(sprintf('Request: "%s %s"', $method, implode('', $url)));
173173

174174
[$host, $port, $url['authority']] = self::dnsResolve($url, $this->multi, $info, $onProgress);
175175

‎src/Symfony/Component/HttpClient/Response/ResponseTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/ResponseTrait.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ public function toStream(bool $throw = true)
204204
$this->getHeaders($throw);
205205
}
206206

207-
return StreamWrapper::createResource($this, null, $this->content, $this->handle && 'stream' === get_resource_type($this->handle) ? $this->handle : null);
207+
$stream = StreamWrapper::createResource($this);
208+
stream_get_meta_data($stream)['wrapper_data']
209+
->bindHandles($this->handle, $this->content);
210+
211+
return $stream;
208212
}
209213

210214
/**

‎src/Symfony/Component/HttpClient/Response/StreamWrapper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/StreamWrapper.php
+14-9Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,9 @@ class StreamWrapper
4343
/**
4444
* Creates a PHP stream resource from a ResponseInterface.
4545
*
46-
* @param resource|null $contentBuffer The seekable resource where the response body is buffered
47-
* @param resource|null $selectHandle The resource handle that should be monitored when
48-
* stream_select() is used on the created stream
49-
*
5046
* @return resource
5147
*/
52-
public static function createResource(ResponseInterface $response, HttpClientInterface $client = null, $contentBuffer = null, $selectHandle = null)
48+
public static function createResource(ResponseInterface $response, HttpClientInterface $client = null)
5349
{
5450
if (null === $client && !method_exists($response, 'stream')) {
5551
throw new \InvalidArgumentException(sprintf('Providing a client to "%s()" is required when the response doesn\'t have any "stream()" method.', __CLASS__));
@@ -63,8 +59,6 @@ public static function createResource(ResponseInterface $response, HttpClientInt
6359
$context = [
6460
'client' => $client ?? $response,
6561
'response' => $response,
66-
'content' => $contentBuffer,
67-
'handle' => $selectHandle,
6862
];
6963

7064
return fopen('symfony://'.$response->getInfo('url'), 'r', false, stream_context_create(['symfony' => $context])) ?: null;
@@ -78,6 +72,17 @@ public function getResponse(): ResponseInterface
7872
return $this->response;
7973
}
8074

75+
/**
76+
* @param resource|null $handle The resource handle that should be monitored when
77+
* stream_select() is used on the created stream
78+
* @param resource|null $content The seekable resource where the response body is buffered
79+
*/
80+
public function bindHandles(&$handle, &$content): void
81+
{
82+
$this->handle = &$handle;
83+
$this->content = &$content;
84+
}
85+
8186
public function stream_open(string $path, string $mode, int $options): bool
8287
{
8388
if ('r' !== $mode) {
@@ -91,8 +96,6 @@ public function stream_open(string $path, string $mode, int $options): bool
9196
$context = stream_context_get_options($this->context)['symfony'] ?? null;
9297
$this->client = $context['client'] ?? null;
9398
$this->response = $context['response'] ?? null;
94-
$this->content = $context['content'] ?? null;
95-
$this->handle = $context['handle'] ?? null;
9699
$this->context = null;
97100

98101
if (null !== $this->client && null !== $this->response) {
@@ -238,6 +241,8 @@ public function stream_seek(int $offset, int $whence = SEEK_SET): bool
238241
public function stream_cast(int $castAs)
239242
{
240243
if (STREAM_CAST_FOR_SELECT === $castAs) {
244+
$this->response->getHeaders(false);
245+
241246
return $this->handle ?? false;
242247
}
243248

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.