|
|
|
|
@ -11,49 +11,25 @@ namespace OC\Http\Client; |
|
|
|
|
use OCP\Http\Client\IResponse; |
|
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class Response |
|
|
|
|
* |
|
|
|
|
* @package OC\Http |
|
|
|
|
*/ |
|
|
|
|
class Response implements IResponse { |
|
|
|
|
/** @var ResponseInterface */ |
|
|
|
|
private $response; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @var bool |
|
|
|
|
*/ |
|
|
|
|
private $stream; |
|
|
|
|
private ResponseInterface $response; |
|
|
|
|
private bool $stream; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param ResponseInterface $response |
|
|
|
|
* @param bool $stream |
|
|
|
|
*/ |
|
|
|
|
public function __construct(ResponseInterface $response, $stream = false) { |
|
|
|
|
public function __construct(ResponseInterface $response, bool $stream = false) { |
|
|
|
|
$this->response = $response; |
|
|
|
|
$this->stream = $stream; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return string|resource |
|
|
|
|
*/ |
|
|
|
|
public function getBody() { |
|
|
|
|
return $this->stream ? |
|
|
|
|
$this->response->getBody()->detach(): |
|
|
|
|
$this->response->getBody()->getContents(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public function getStatusCode(): int { |
|
|
|
|
return $this->response->getStatusCode(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string $key |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
public function getHeader(string $key): string { |
|
|
|
|
$headers = $this->response->getHeader($key); |
|
|
|
|
|
|
|
|
|
@ -64,9 +40,6 @@ class Response implements IResponse { |
|
|
|
|
return $headers[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function getHeaders(): array { |
|
|
|
|
return $this->response->getHeaders(); |
|
|
|
|
} |
|
|
|
|
|