From b67d39508909e72913c97a050b25b51a9b1bd707 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 29 Aug 2015 14:52:37 +0200 Subject: allow streamed responses in http client --- lib/private/http/client/client.php | 3 ++- lib/private/http/client/response.php | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/private') diff --git a/lib/private/http/client/client.php b/lib/private/http/client/client.php index 323fc0d324f..b0aff10a413 100644 --- a/lib/private/http/client/client.php +++ b/lib/private/http/client/client.php @@ -120,7 +120,8 @@ class Client implements IClient { */ public function get($uri, array $options = []) { $response = $this->client->get($uri, $options); - return new Response($response); + $isStream = isset($options['stream']) && $options['stream']; + return new Response($response, $isStream); } /** diff --git a/lib/private/http/client/response.php b/lib/private/http/client/response.php index 4e9df51d77f..558482491d1 100644 --- a/lib/private/http/client/response.php +++ b/lib/private/http/client/response.php @@ -33,18 +33,27 @@ class Response implements IResponse { /** @var GuzzleResponse */ private $response; + /** + * @var bool + */ + private $stream; + /** * @param GuzzleResponse $response + * @param bool $stream */ - public function __construct(GuzzleResponse $response) { + public function __construct(GuzzleResponse $response, $stream = false) { $this->response = $response; + $this->stream = $stream; } /** - * @return string + * @return string|resource */ public function getBody() { - return $this->response->getBody()->getContents(); + return $this->stream ? + $this->response->getBody()->detach(): + $this->response->getBody()->getContents(); } /** -- cgit v1.2.3