Response.php 1.8 KB

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