2015-03-16 06:28:23 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-01-16 10:41:41 -05:00
|
|
|
declare(strict_types=1);
|
2015-03-16 06:28:23 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-03-16 06:28:23 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Http\Client;
|
|
|
|
|
|
|
|
|
|
use OCP\Http\Client\IResponse;
|
2018-02-08 07:39:27 -05:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2015-03-16 06:28:23 -04:00
|
|
|
|
|
|
|
|
class Response implements IResponse {
|
2025-06-25 08:57:08 -04:00
|
|
|
private ResponseInterface $response;
|
|
|
|
|
private bool $stream;
|
2015-08-29 08:52:37 -04:00
|
|
|
|
2025-06-25 08:57:08 -04:00
|
|
|
public function __construct(ResponseInterface $response, bool $stream = false) {
|
2015-03-16 06:28:23 -04:00
|
|
|
$this->response = $response;
|
2015-08-29 08:52:37 -04:00
|
|
|
$this->stream = $stream;
|
2015-03-16 06:28:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBody() {
|
2025-06-30 09:04:05 -04:00
|
|
|
return $this->stream
|
|
|
|
|
? $this->response->getBody()->detach()
|
|
|
|
|
:$this->response->getBody()->getContents();
|
2015-03-16 06:28:23 -04:00
|
|
|
}
|
|
|
|
|
|
2018-01-16 10:41:41 -05:00
|
|
|
public function getStatusCode(): int {
|
2015-03-16 06:28:23 -04:00
|
|
|
return $this->response->getStatusCode();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 10:41:41 -05:00
|
|
|
public function getHeader(string $key): string {
|
2019-01-07 16:08:32 -05:00
|
|
|
$headers = $this->response->getHeader($key);
|
|
|
|
|
|
|
|
|
|
if (count($headers) === 0) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $headers[0];
|
2015-03-16 06:28:23 -04:00
|
|
|
}
|
|
|
|
|
|
2018-01-16 10:41:41 -05:00
|
|
|
public function getHeaders(): array {
|
2015-03-16 06:28:23 -04:00
|
|
|
return $this->response->getHeaders();
|
|
|
|
|
}
|
|
|
|
|
}
|