allow streamed responses in http client

remotes/origin/db-empty-migrate
Robin Appelman 10 years ago
parent faa62d1799
commit b67d395089
  1. 3
      lib/private/http/client/client.php
  2. 15
      lib/private/http/client/response.php
  3. 2
      lib/public/http/client/iresponse.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);
}
/**

@ -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();
}
/**

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

Loading…
Cancel
Save