1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Lukas Reschke <[email protected]> |
4
|
|
|
* @author Robin Appelman <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) 2015, 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
|
|
|
|
23
|
|
|
namespace OC\Http\Client; |
24
|
|
|
|
25
|
|
|
use OCP\Http\Client\IResponse; |
26
|
|
|
use GuzzleHttp\Message\Response as GuzzleResponse; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class Response |
30
|
|
|
* |
31
|
|
|
* @package OC\Http |
32
|
|
|
*/ |
33
|
|
|
class Response implements IResponse { |
34
|
|
|
/** @var GuzzleResponse */ |
35
|
|
|
private $response; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
private $stream; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param GuzzleResponse $response |
44
|
|
|
* @param bool $stream |
45
|
|
|
*/ |
46
|
7 |
|
public function __construct(GuzzleResponse $response, $stream = false) { |
47
|
7 |
|
$this->response = $response; |
48
|
7 |
|
$this->stream = $stream; |
49
|
7 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string|resource |
53
|
|
|
*/ |
54
|
|
|
public function getBody() { |
55
|
|
|
return $this->stream ? |
56
|
|
|
$this->response->getBody()->detach(): |
57
|
|
|
$this->response->getBody()->getContents(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
6 |
|
public function getStatusCode() { |
64
|
6 |
|
return $this->response->getStatusCode(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param $key |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
1 |
|
public function getHeader($key) { |
72
|
1 |
|
return $this->response->getHeader($key); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
public function getHeaders() { |
79
|
|
|
return $this->response->getHeaders(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|