allow streamed responses in http client

This commit is contained in:
Robin Appelman 2015-08-29 14:52:37 +02:00
parent faa62d1799
commit b67d395089
3 changed files with 16 additions and 6 deletions

View File

@ -120,7 +120,8 @@ class Client implements IClient {
*/ */
public function get($uri, array $options = []) { public function get($uri, array $options = []) {
$response = $this->client->get($uri, $options); $response = $this->client->get($uri, $options);
return new Response($response); $isStream = isset($options['stream']) && $options['stream'];
return new Response($response, $isStream);
} }
/** /**

View File

@ -34,17 +34,26 @@ class Response implements IResponse {
private $response; private $response;
/** /**
* @param GuzzleResponse $response * @var bool
*/ */
public function __construct(GuzzleResponse $response) { private $stream;
/**
* @param GuzzleResponse $response
* @param bool $stream
*/
public function __construct(GuzzleResponse $response, $stream = false) {
$this->response = $response; $this->response = $response;
$this->stream = $stream;
} }
/** /**
* @return string * @return string|resource
*/ */
public function getBody() { public function getBody() {
return $this->response->getBody()->getContents(); return $this->stream ?
$this->response->getBody()->detach():
$this->response->getBody()->getContents();
} }
/** /**

View File

@ -30,7 +30,7 @@ namespace OCP\Http\Client;
*/ */
interface IResponse { interface IResponse {
/** /**
* @return string * @return string|resource
* @since 8.1.0 * @since 8.1.0
*/ */
public function getBody(); public function getBody();