You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.8 KiB

10 years ago
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. * @author Robin Appelman <icewind@owncloud.com>
  5. *
  6. * @copyright Copyright (c) 2016, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Http\Client;
  23. use OCP\Http\Client\IResponse;
  24. use GuzzleHttp\Message\Response as GuzzleResponse;
  25. /**
  26. * Class Response
  27. *
  28. * @package OC\Http
  29. */
  30. class Response implements IResponse {
  31. /** @var GuzzleResponse */
  32. private $response;
  33. /**
  34. * @var bool
  35. */
  36. private $stream;
  37. /**
  38. * @param GuzzleResponse $response
  39. * @param bool $stream
  40. */
  41. public function __construct(GuzzleResponse $response, $stream = false) {
  42. $this->response = $response;
  43. $this->stream = $stream;
  44. }
  45. /**
  46. * @return string|resource
  47. */
  48. public function getBody() {
  49. return $this->stream ?
  50. $this->response->getBody()->detach():
  51. $this->response->getBody()->getContents();
  52. }
  53. /**
  54. * @return int
  55. */
  56. public function getStatusCode() {
  57. return $this->response->getStatusCode();
  58. }
  59. /**
  60. * @param $key
  61. * @return string
  62. */
  63. public function getHeader($key) {
  64. return $this->response->getHeader($key);
  65. }
  66. /**
  67. * @return array
  68. */
  69. public function getHeaders() {
  70. return $this->response->getHeaders();
  71. }
  72. }