@@ -36,25 +36,25 @@ |
||
| 36 | 36 | * @package OC\Http |
| 37 | 37 | */ |
| 38 | 38 | class ClientService implements IClientService { |
| 39 | - /** @var IConfig */ |
|
| 40 | - private $config; |
|
| 41 | - /** @var ICertificateManager */ |
|
| 42 | - private $certificateManager; |
|
| 39 | + /** @var IConfig */ |
|
| 40 | + private $config; |
|
| 41 | + /** @var ICertificateManager */ |
|
| 42 | + private $certificateManager; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param IConfig $config |
|
| 46 | - * @param ICertificateManager $certificateManager |
|
| 47 | - */ |
|
| 48 | - public function __construct(IConfig $config, |
|
| 49 | - ICertificateManager $certificateManager) { |
|
| 50 | - $this->config = $config; |
|
| 51 | - $this->certificateManager = $certificateManager; |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * @param IConfig $config |
|
| 46 | + * @param ICertificateManager $certificateManager |
|
| 47 | + */ |
|
| 48 | + public function __construct(IConfig $config, |
|
| 49 | + ICertificateManager $certificateManager) { |
|
| 50 | + $this->config = $config; |
|
| 51 | + $this->certificateManager = $certificateManager; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return Client |
|
| 56 | - */ |
|
| 57 | - public function newClient(): IClient { |
|
| 58 | - return new Client($this->config, $this->certificateManager, new GuzzleClient(), HandlerStack::create()); |
|
| 59 | - } |
|
| 54 | + /** |
|
| 55 | + * @return Client |
|
| 56 | + */ |
|
| 57 | + public function newClient(): IClient { |
|
| 58 | + return new Client($this->config, $this->certificateManager, new GuzzleClient(), HandlerStack::create()); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -39,297 +39,297 @@ |
||
| 39 | 39 | * @package OC\Http |
| 40 | 40 | */ |
| 41 | 41 | class Client implements IClient { |
| 42 | - /** @var GuzzleClient */ |
|
| 43 | - private $client; |
|
| 44 | - /** @var IConfig */ |
|
| 45 | - private $config; |
|
| 46 | - /** @var ICertificateManager */ |
|
| 47 | - private $certificateManager; |
|
| 48 | - private $configured = false; |
|
| 49 | - /** @var HandlerStack */ |
|
| 50 | - private $stack; |
|
| 42 | + /** @var GuzzleClient */ |
|
| 43 | + private $client; |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + private $config; |
|
| 46 | + /** @var ICertificateManager */ |
|
| 47 | + private $certificateManager; |
|
| 48 | + private $configured = false; |
|
| 49 | + /** @var HandlerStack */ |
|
| 50 | + private $stack; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param IConfig $config |
|
| 54 | - * @param ICertificateManager $certificateManager |
|
| 55 | - * @param GuzzleClient $client |
|
| 56 | - */ |
|
| 57 | - public function __construct( |
|
| 58 | - IConfig $config, |
|
| 59 | - ICertificateManager $certificateManager, |
|
| 60 | - GuzzleClient $client, |
|
| 61 | - HandlerStack $stack |
|
| 62 | - ) { |
|
| 63 | - $this->config = $config; |
|
| 64 | - $this->client = $client; |
|
| 65 | - $this->stack = $stack; |
|
| 66 | - $this->certificateManager = $certificateManager; |
|
| 67 | - } |
|
| 52 | + /** |
|
| 53 | + * @param IConfig $config |
|
| 54 | + * @param ICertificateManager $certificateManager |
|
| 55 | + * @param GuzzleClient $client |
|
| 56 | + */ |
|
| 57 | + public function __construct( |
|
| 58 | + IConfig $config, |
|
| 59 | + ICertificateManager $certificateManager, |
|
| 60 | + GuzzleClient $client, |
|
| 61 | + HandlerStack $stack |
|
| 62 | + ) { |
|
| 63 | + $this->config = $config; |
|
| 64 | + $this->client = $client; |
|
| 65 | + $this->stack = $stack; |
|
| 66 | + $this->certificateManager = $certificateManager; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Sets the default options to the client |
|
| 71 | - */ |
|
| 72 | - private function setDefaultOptions() { |
|
| 73 | - if ($this->configured) { |
|
| 74 | - return; |
|
| 75 | - } |
|
| 76 | - $this->configured = true; |
|
| 69 | + /** |
|
| 70 | + * Sets the default options to the client |
|
| 71 | + */ |
|
| 72 | + private function setDefaultOptions() { |
|
| 73 | + if ($this->configured) { |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | + $this->configured = true; |
|
| 77 | 77 | |
| 78 | - $this->stack->push(Middleware::mapRequest(function (RequestInterface $request) { |
|
| 79 | - return $request |
|
| 80 | - ->withHeader('User-Agent', 'Nextcloud Server Crawler'); |
|
| 81 | - })); |
|
| 82 | - } |
|
| 78 | + $this->stack->push(Middleware::mapRequest(function (RequestInterface $request) { |
|
| 79 | + return $request |
|
| 80 | + ->withHeader('User-Agent', 'Nextcloud Server Crawler'); |
|
| 81 | + })); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - private function getRequestOptions() { |
|
| 85 | - $options = [ |
|
| 86 | - 'verify' => $this->getCertBundle(), |
|
| 87 | - ]; |
|
| 88 | - $proxyUri = $this->getProxyUri(); |
|
| 89 | - if ($proxyUri !== '') { |
|
| 90 | - $options['proxy'] = $proxyUri; |
|
| 91 | - } |
|
| 92 | - } |
|
| 84 | + private function getRequestOptions() { |
|
| 85 | + $options = [ |
|
| 86 | + 'verify' => $this->getCertBundle(), |
|
| 87 | + ]; |
|
| 88 | + $proxyUri = $this->getProxyUri(); |
|
| 89 | + if ($proxyUri !== '') { |
|
| 90 | + $options['proxy'] = $proxyUri; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - private function getCertBundle() { |
|
| 95 | - if ($this->certificateManager->listCertificates() !== []) { |
|
| 96 | - return $this->certificateManager->getAbsoluteBundlePath(); |
|
| 97 | - } else { |
|
| 98 | - // If the instance is not yet setup we need to use the static path as |
|
| 99 | - // $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate |
|
| 100 | - // a view |
|
| 101 | - if ($this->config->getSystemValue('installed', false)) { |
|
| 102 | - return $this->certificateManager->getAbsoluteBundlePath(null); |
|
| 103 | - } else { |
|
| 104 | - return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 94 | + private function getCertBundle() { |
|
| 95 | + if ($this->certificateManager->listCertificates() !== []) { |
|
| 96 | + return $this->certificateManager->getAbsoluteBundlePath(); |
|
| 97 | + } else { |
|
| 98 | + // If the instance is not yet setup we need to use the static path as |
|
| 99 | + // $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate |
|
| 100 | + // a view |
|
| 101 | + if ($this->config->getSystemValue('installed', false)) { |
|
| 102 | + return $this->certificateManager->getAbsoluteBundlePath(null); |
|
| 103 | + } else { |
|
| 104 | + return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Get the proxy URI |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - private function getProxyUri(): string { |
|
| 115 | - $proxyHost = $this->config->getSystemValue('proxy', null); |
|
| 116 | - $proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null); |
|
| 117 | - $proxyUri = ''; |
|
| 109 | + /** |
|
| 110 | + * Get the proxy URI |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + private function getProxyUri(): string { |
|
| 115 | + $proxyHost = $this->config->getSystemValue('proxy', null); |
|
| 116 | + $proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null); |
|
| 117 | + $proxyUri = ''; |
|
| 118 | 118 | |
| 119 | - if ($proxyUserPwd !== null) { |
|
| 120 | - $proxyUri .= $proxyUserPwd . '@'; |
|
| 121 | - } |
|
| 122 | - if ($proxyHost !== null) { |
|
| 123 | - $proxyUri .= $proxyHost; |
|
| 124 | - } |
|
| 119 | + if ($proxyUserPwd !== null) { |
|
| 120 | + $proxyUri .= $proxyUserPwd . '@'; |
|
| 121 | + } |
|
| 122 | + if ($proxyHost !== null) { |
|
| 123 | + $proxyUri .= $proxyHost; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $proxyUri; |
|
| 127 | - } |
|
| 126 | + return $proxyUri; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Sends a GET request |
|
| 131 | - * |
|
| 132 | - * @param string $uri |
|
| 133 | - * @param array $options Array such as |
|
| 134 | - * 'query' => [ |
|
| 135 | - * 'field' => 'abc', |
|
| 136 | - * 'other_field' => '123', |
|
| 137 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 138 | - * ], |
|
| 139 | - * 'headers' => [ |
|
| 140 | - * 'foo' => 'bar', |
|
| 141 | - * ], |
|
| 142 | - * 'cookies' => [' |
|
| 143 | - * 'foo' => 'bar', |
|
| 144 | - * ], |
|
| 145 | - * 'allow_redirects' => [ |
|
| 146 | - * 'max' => 10, // allow at most 10 redirects. |
|
| 147 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 148 | - * 'referer' => true, // add a Referer header |
|
| 149 | - * 'protocols' => ['https'] // only allow https URLs |
|
| 150 | - * ], |
|
| 151 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 152 | - * 'verify' => true, // bool or string to CA file |
|
| 153 | - * 'debug' => true, |
|
| 154 | - * 'timeout' => 5, |
|
| 155 | - * @return IResponse |
|
| 156 | - * @throws \Exception If the request could not get completed |
|
| 157 | - */ |
|
| 158 | - public function get(string $uri, array $options = []): IResponse { |
|
| 159 | - $this->setDefaultOptions(); |
|
| 160 | - $response = $this->client->get($uri, array_merge($options, $this->getRequestOptions())); |
|
| 161 | - $isStream = isset($options['stream']) && $options['stream']; |
|
| 162 | - return new Response($response, $isStream); |
|
| 163 | - } |
|
| 129 | + /** |
|
| 130 | + * Sends a GET request |
|
| 131 | + * |
|
| 132 | + * @param string $uri |
|
| 133 | + * @param array $options Array such as |
|
| 134 | + * 'query' => [ |
|
| 135 | + * 'field' => 'abc', |
|
| 136 | + * 'other_field' => '123', |
|
| 137 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 138 | + * ], |
|
| 139 | + * 'headers' => [ |
|
| 140 | + * 'foo' => 'bar', |
|
| 141 | + * ], |
|
| 142 | + * 'cookies' => [' |
|
| 143 | + * 'foo' => 'bar', |
|
| 144 | + * ], |
|
| 145 | + * 'allow_redirects' => [ |
|
| 146 | + * 'max' => 10, // allow at most 10 redirects. |
|
| 147 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 148 | + * 'referer' => true, // add a Referer header |
|
| 149 | + * 'protocols' => ['https'] // only allow https URLs |
|
| 150 | + * ], |
|
| 151 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 152 | + * 'verify' => true, // bool or string to CA file |
|
| 153 | + * 'debug' => true, |
|
| 154 | + * 'timeout' => 5, |
|
| 155 | + * @return IResponse |
|
| 156 | + * @throws \Exception If the request could not get completed |
|
| 157 | + */ |
|
| 158 | + public function get(string $uri, array $options = []): IResponse { |
|
| 159 | + $this->setDefaultOptions(); |
|
| 160 | + $response = $this->client->get($uri, array_merge($options, $this->getRequestOptions())); |
|
| 161 | + $isStream = isset($options['stream']) && $options['stream']; |
|
| 162 | + return new Response($response, $isStream); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Sends a HEAD request |
|
| 167 | - * |
|
| 168 | - * @param string $uri |
|
| 169 | - * @param array $options Array such as |
|
| 170 | - * 'headers' => [ |
|
| 171 | - * 'foo' => 'bar', |
|
| 172 | - * ], |
|
| 173 | - * 'cookies' => [' |
|
| 174 | - * 'foo' => 'bar', |
|
| 175 | - * ], |
|
| 176 | - * 'allow_redirects' => [ |
|
| 177 | - * 'max' => 10, // allow at most 10 redirects. |
|
| 178 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 179 | - * 'referer' => true, // add a Referer header |
|
| 180 | - * 'protocols' => ['https'] // only allow https URLs |
|
| 181 | - * ], |
|
| 182 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 183 | - * 'verify' => true, // bool or string to CA file |
|
| 184 | - * 'debug' => true, |
|
| 185 | - * 'timeout' => 5, |
|
| 186 | - * @return IResponse |
|
| 187 | - * @throws \Exception If the request could not get completed |
|
| 188 | - */ |
|
| 189 | - public function head(string $uri, array $options = []): IResponse { |
|
| 190 | - $this->setDefaultOptions(); |
|
| 191 | - $response = $this->client->head($uri, array_merge($options, $this->getRequestOptions())); |
|
| 192 | - return new Response($response); |
|
| 193 | - } |
|
| 165 | + /** |
|
| 166 | + * Sends a HEAD request |
|
| 167 | + * |
|
| 168 | + * @param string $uri |
|
| 169 | + * @param array $options Array such as |
|
| 170 | + * 'headers' => [ |
|
| 171 | + * 'foo' => 'bar', |
|
| 172 | + * ], |
|
| 173 | + * 'cookies' => [' |
|
| 174 | + * 'foo' => 'bar', |
|
| 175 | + * ], |
|
| 176 | + * 'allow_redirects' => [ |
|
| 177 | + * 'max' => 10, // allow at most 10 redirects. |
|
| 178 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 179 | + * 'referer' => true, // add a Referer header |
|
| 180 | + * 'protocols' => ['https'] // only allow https URLs |
|
| 181 | + * ], |
|
| 182 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 183 | + * 'verify' => true, // bool or string to CA file |
|
| 184 | + * 'debug' => true, |
|
| 185 | + * 'timeout' => 5, |
|
| 186 | + * @return IResponse |
|
| 187 | + * @throws \Exception If the request could not get completed |
|
| 188 | + */ |
|
| 189 | + public function head(string $uri, array $options = []): IResponse { |
|
| 190 | + $this->setDefaultOptions(); |
|
| 191 | + $response = $this->client->head($uri, array_merge($options, $this->getRequestOptions())); |
|
| 192 | + return new Response($response); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Sends a POST request |
|
| 197 | - * |
|
| 198 | - * @param string $uri |
|
| 199 | - * @param array $options Array such as |
|
| 200 | - * 'body' => [ |
|
| 201 | - * 'field' => 'abc', |
|
| 202 | - * 'other_field' => '123', |
|
| 203 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 204 | - * ], |
|
| 205 | - * 'headers' => [ |
|
| 206 | - * 'foo' => 'bar', |
|
| 207 | - * ], |
|
| 208 | - * 'cookies' => [' |
|
| 209 | - * 'foo' => 'bar', |
|
| 210 | - * ], |
|
| 211 | - * 'allow_redirects' => [ |
|
| 212 | - * 'max' => 10, // allow at most 10 redirects. |
|
| 213 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 214 | - * 'referer' => true, // add a Referer header |
|
| 215 | - * 'protocols' => ['https'] // only allow https URLs |
|
| 216 | - * ], |
|
| 217 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 218 | - * 'verify' => true, // bool or string to CA file |
|
| 219 | - * 'debug' => true, |
|
| 220 | - * 'timeout' => 5, |
|
| 221 | - * @return IResponse |
|
| 222 | - * @throws \Exception If the request could not get completed |
|
| 223 | - */ |
|
| 224 | - public function post(string $uri, array $options = []): IResponse { |
|
| 225 | - $this->setDefaultOptions(); |
|
| 226 | - $response = $this->client->post($uri, array_merge($options, $this->getRequestOptions())); |
|
| 227 | - return new Response($response); |
|
| 228 | - } |
|
| 195 | + /** |
|
| 196 | + * Sends a POST request |
|
| 197 | + * |
|
| 198 | + * @param string $uri |
|
| 199 | + * @param array $options Array such as |
|
| 200 | + * 'body' => [ |
|
| 201 | + * 'field' => 'abc', |
|
| 202 | + * 'other_field' => '123', |
|
| 203 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 204 | + * ], |
|
| 205 | + * 'headers' => [ |
|
| 206 | + * 'foo' => 'bar', |
|
| 207 | + * ], |
|
| 208 | + * 'cookies' => [' |
|
| 209 | + * 'foo' => 'bar', |
|
| 210 | + * ], |
|
| 211 | + * 'allow_redirects' => [ |
|
| 212 | + * 'max' => 10, // allow at most 10 redirects. |
|
| 213 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 214 | + * 'referer' => true, // add a Referer header |
|
| 215 | + * 'protocols' => ['https'] // only allow https URLs |
|
| 216 | + * ], |
|
| 217 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 218 | + * 'verify' => true, // bool or string to CA file |
|
| 219 | + * 'debug' => true, |
|
| 220 | + * 'timeout' => 5, |
|
| 221 | + * @return IResponse |
|
| 222 | + * @throws \Exception If the request could not get completed |
|
| 223 | + */ |
|
| 224 | + public function post(string $uri, array $options = []): IResponse { |
|
| 225 | + $this->setDefaultOptions(); |
|
| 226 | + $response = $this->client->post($uri, array_merge($options, $this->getRequestOptions())); |
|
| 227 | + return new Response($response); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Sends a PUT request |
|
| 232 | - * |
|
| 233 | - * @param string $uri |
|
| 234 | - * @param array $options Array such as |
|
| 235 | - * 'body' => [ |
|
| 236 | - * 'field' => 'abc', |
|
| 237 | - * 'other_field' => '123', |
|
| 238 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 239 | - * ], |
|
| 240 | - * 'headers' => [ |
|
| 241 | - * 'foo' => 'bar', |
|
| 242 | - * ], |
|
| 243 | - * 'cookies' => [' |
|
| 244 | - * 'foo' => 'bar', |
|
| 245 | - * ], |
|
| 246 | - * 'allow_redirects' => [ |
|
| 247 | - * 'max' => 10, // allow at most 10 redirects. |
|
| 248 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 249 | - * 'referer' => true, // add a Referer header |
|
| 250 | - * 'protocols' => ['https'] // only allow https URLs |
|
| 251 | - * ], |
|
| 252 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 253 | - * 'verify' => true, // bool or string to CA file |
|
| 254 | - * 'debug' => true, |
|
| 255 | - * 'timeout' => 5, |
|
| 256 | - * @return IResponse |
|
| 257 | - * @throws \Exception If the request could not get completed |
|
| 258 | - */ |
|
| 259 | - public function put(string $uri, array $options = []): IResponse { |
|
| 260 | - $this->setDefaultOptions(); |
|
| 261 | - $response = $this->client->put($uri, array_merge($options, $this->getRequestOptions())); |
|
| 262 | - return new Response($response); |
|
| 263 | - } |
|
| 230 | + /** |
|
| 231 | + * Sends a PUT request |
|
| 232 | + * |
|
| 233 | + * @param string $uri |
|
| 234 | + * @param array $options Array such as |
|
| 235 | + * 'body' => [ |
|
| 236 | + * 'field' => 'abc', |
|
| 237 | + * 'other_field' => '123', |
|
| 238 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 239 | + * ], |
|
| 240 | + * 'headers' => [ |
|
| 241 | + * 'foo' => 'bar', |
|
| 242 | + * ], |
|
| 243 | + * 'cookies' => [' |
|
| 244 | + * 'foo' => 'bar', |
|
| 245 | + * ], |
|
| 246 | + * 'allow_redirects' => [ |
|
| 247 | + * 'max' => 10, // allow at most 10 redirects. |
|
| 248 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 249 | + * 'referer' => true, // add a Referer header |
|
| 250 | + * 'protocols' => ['https'] // only allow https URLs |
|
| 251 | + * ], |
|
| 252 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 253 | + * 'verify' => true, // bool or string to CA file |
|
| 254 | + * 'debug' => true, |
|
| 255 | + * 'timeout' => 5, |
|
| 256 | + * @return IResponse |
|
| 257 | + * @throws \Exception If the request could not get completed |
|
| 258 | + */ |
|
| 259 | + public function put(string $uri, array $options = []): IResponse { |
|
| 260 | + $this->setDefaultOptions(); |
|
| 261 | + $response = $this->client->put($uri, array_merge($options, $this->getRequestOptions())); |
|
| 262 | + return new Response($response); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Sends a DELETE request |
|
| 267 | - * |
|
| 268 | - * @param string $uri |
|
| 269 | - * @param array $options Array such as |
|
| 270 | - * 'body' => [ |
|
| 271 | - * 'field' => 'abc', |
|
| 272 | - * 'other_field' => '123', |
|
| 273 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 274 | - * ], |
|
| 275 | - * 'headers' => [ |
|
| 276 | - * 'foo' => 'bar', |
|
| 277 | - * ], |
|
| 278 | - * 'cookies' => [' |
|
| 279 | - * 'foo' => 'bar', |
|
| 280 | - * ], |
|
| 281 | - * 'allow_redirects' => [ |
|
| 282 | - * 'max' => 10, // allow at most 10 redirects. |
|
| 283 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 284 | - * 'referer' => true, // add a Referer header |
|
| 285 | - * 'protocols' => ['https'] // only allow https URLs |
|
| 286 | - * ], |
|
| 287 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 288 | - * 'verify' => true, // bool or string to CA file |
|
| 289 | - * 'debug' => true, |
|
| 290 | - * 'timeout' => 5, |
|
| 291 | - * @return IResponse |
|
| 292 | - * @throws \Exception If the request could not get completed |
|
| 293 | - */ |
|
| 294 | - public function delete(string $uri, array $options = []): IResponse { |
|
| 295 | - $this->setDefaultOptions(); |
|
| 296 | - $response = $this->client->delete($uri, array_merge($options, $this->getRequestOptions())); |
|
| 297 | - return new Response($response); |
|
| 298 | - } |
|
| 265 | + /** |
|
| 266 | + * Sends a DELETE request |
|
| 267 | + * |
|
| 268 | + * @param string $uri |
|
| 269 | + * @param array $options Array such as |
|
| 270 | + * 'body' => [ |
|
| 271 | + * 'field' => 'abc', |
|
| 272 | + * 'other_field' => '123', |
|
| 273 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 274 | + * ], |
|
| 275 | + * 'headers' => [ |
|
| 276 | + * 'foo' => 'bar', |
|
| 277 | + * ], |
|
| 278 | + * 'cookies' => [' |
|
| 279 | + * 'foo' => 'bar', |
|
| 280 | + * ], |
|
| 281 | + * 'allow_redirects' => [ |
|
| 282 | + * 'max' => 10, // allow at most 10 redirects. |
|
| 283 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 284 | + * 'referer' => true, // add a Referer header |
|
| 285 | + * 'protocols' => ['https'] // only allow https URLs |
|
| 286 | + * ], |
|
| 287 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 288 | + * 'verify' => true, // bool or string to CA file |
|
| 289 | + * 'debug' => true, |
|
| 290 | + * 'timeout' => 5, |
|
| 291 | + * @return IResponse |
|
| 292 | + * @throws \Exception If the request could not get completed |
|
| 293 | + */ |
|
| 294 | + public function delete(string $uri, array $options = []): IResponse { |
|
| 295 | + $this->setDefaultOptions(); |
|
| 296 | + $response = $this->client->delete($uri, array_merge($options, $this->getRequestOptions())); |
|
| 297 | + return new Response($response); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Sends a options request |
|
| 303 | - * |
|
| 304 | - * @param string $uri |
|
| 305 | - * @param array $options Array such as |
|
| 306 | - * 'body' => [ |
|
| 307 | - * 'field' => 'abc', |
|
| 308 | - * 'other_field' => '123', |
|
| 309 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 310 | - * ], |
|
| 311 | - * 'headers' => [ |
|
| 312 | - * 'foo' => 'bar', |
|
| 313 | - * ], |
|
| 314 | - * 'cookies' => [' |
|
| 315 | - * 'foo' => 'bar', |
|
| 316 | - * ], |
|
| 317 | - * 'allow_redirects' => [ |
|
| 318 | - * 'max' => 10, // allow at most 10 redirects. |
|
| 319 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 320 | - * 'referer' => true, // add a Referer header |
|
| 321 | - * 'protocols' => ['https'] // only allow https URLs |
|
| 322 | - * ], |
|
| 323 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 324 | - * 'verify' => true, // bool or string to CA file |
|
| 325 | - * 'debug' => true, |
|
| 326 | - * 'timeout' => 5, |
|
| 327 | - * @return IResponse |
|
| 328 | - * @throws \Exception If the request could not get completed |
|
| 329 | - */ |
|
| 330 | - public function options(string $uri, array $options = []): IResponse { |
|
| 331 | - $this->setDefaultOptions(); |
|
| 332 | - $response = $this->client->options($uri, array_merge($options, $this->getRequestOptions())); |
|
| 333 | - return new Response($response); |
|
| 334 | - } |
|
| 301 | + /** |
|
| 302 | + * Sends a options request |
|
| 303 | + * |
|
| 304 | + * @param string $uri |
|
| 305 | + * @param array $options Array such as |
|
| 306 | + * 'body' => [ |
|
| 307 | + * 'field' => 'abc', |
|
| 308 | + * 'other_field' => '123', |
|
| 309 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
| 310 | + * ], |
|
| 311 | + * 'headers' => [ |
|
| 312 | + * 'foo' => 'bar', |
|
| 313 | + * ], |
|
| 314 | + * 'cookies' => [' |
|
| 315 | + * 'foo' => 'bar', |
|
| 316 | + * ], |
|
| 317 | + * 'allow_redirects' => [ |
|
| 318 | + * 'max' => 10, // allow at most 10 redirects. |
|
| 319 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
| 320 | + * 'referer' => true, // add a Referer header |
|
| 321 | + * 'protocols' => ['https'] // only allow https URLs |
|
| 322 | + * ], |
|
| 323 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
| 324 | + * 'verify' => true, // bool or string to CA file |
|
| 325 | + * 'debug' => true, |
|
| 326 | + * 'timeout' => 5, |
|
| 327 | + * @return IResponse |
|
| 328 | + * @throws \Exception If the request could not get completed |
|
| 329 | + */ |
|
| 330 | + public function options(string $uri, array $options = []): IResponse { |
|
| 331 | + $this->setDefaultOptions(); |
|
| 332 | + $response = $this->client->options($uri, array_merge($options, $this->getRequestOptions())); |
|
| 333 | + return new Response($response); |
|
| 334 | + } |
|
| 335 | 335 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | $this->configured = true; |
| 77 | 77 | |
| 78 | - $this->stack->push(Middleware::mapRequest(function (RequestInterface $request) { |
|
| 78 | + $this->stack->push(Middleware::mapRequest(function(RequestInterface $request) { |
|
| 79 | 79 | return $request |
| 80 | 80 | ->withHeader('User-Agent', 'Nextcloud Server Crawler'); |
| 81 | 81 | })); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | if ($this->config->getSystemValue('installed', false)) { |
| 102 | 102 | return $this->certificateManager->getAbsoluteBundlePath(null); |
| 103 | 103 | } else { |
| 104 | - return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'; |
|
| 104 | + return \OC::$SERVERROOT.'/resources/config/ca-bundle.crt'; |
|
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $proxyUri = ''; |
| 118 | 118 | |
| 119 | 119 | if ($proxyUserPwd !== null) { |
| 120 | - $proxyUri .= $proxyUserPwd . '@'; |
|
| 120 | + $proxyUri .= $proxyUserPwd.'@'; |
|
| 121 | 121 | } |
| 122 | 122 | if ($proxyHost !== null) { |
| 123 | 123 | $proxyUri .= $proxyHost; |
@@ -33,51 +33,51 @@ |
||
| 33 | 33 | * @package OC\Http |
| 34 | 34 | */ |
| 35 | 35 | class Response implements IResponse { |
| 36 | - /** @var ResponseInterface */ |
|
| 37 | - private $response; |
|
| 36 | + /** @var ResponseInterface */ |
|
| 37 | + private $response; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var bool |
|
| 41 | - */ |
|
| 42 | - private $stream; |
|
| 39 | + /** |
|
| 40 | + * @var bool |
|
| 41 | + */ |
|
| 42 | + private $stream; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param ResponseInterface $response |
|
| 46 | - * @param bool $stream |
|
| 47 | - */ |
|
| 48 | - public function __construct(ResponseInterface $response, $stream = false) { |
|
| 49 | - $this->response = $response; |
|
| 50 | - $this->stream = $stream; |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * @param ResponseInterface $response |
|
| 46 | + * @param bool $stream |
|
| 47 | + */ |
|
| 48 | + public function __construct(ResponseInterface $response, $stream = false) { |
|
| 49 | + $this->response = $response; |
|
| 50 | + $this->stream = $stream; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return string|resource |
|
| 55 | - */ |
|
| 56 | - public function getBody() { |
|
| 57 | - return $this->stream ? |
|
| 58 | - $this->response->getBody()->detach(): |
|
| 59 | - $this->response->getBody()->getContents(); |
|
| 60 | - } |
|
| 53 | + /** |
|
| 54 | + * @return string|resource |
|
| 55 | + */ |
|
| 56 | + public function getBody() { |
|
| 57 | + return $this->stream ? |
|
| 58 | + $this->response->getBody()->detach(): |
|
| 59 | + $this->response->getBody()->getContents(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return int |
|
| 64 | - */ |
|
| 65 | - public function getStatusCode(): int { |
|
| 66 | - return $this->response->getStatusCode(); |
|
| 67 | - } |
|
| 62 | + /** |
|
| 63 | + * @return int |
|
| 64 | + */ |
|
| 65 | + public function getStatusCode(): int { |
|
| 66 | + return $this->response->getStatusCode(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param string $key |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function getHeader(string $key): string { |
|
| 74 | - return $this->response->getHeader($key)[0]; |
|
| 75 | - } |
|
| 69 | + /** |
|
| 70 | + * @param string $key |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function getHeader(string $key): string { |
|
| 74 | + return $this->response->getHeader($key)[0]; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 80 | - public function getHeaders(): array { |
|
| 81 | - return $this->response->getHeaders(); |
|
| 82 | - } |
|
| 77 | + /** |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | + public function getHeaders(): array { |
|
| 81 | + return $this->response->getHeaders(); |
|
| 82 | + } |
|
| 83 | 83 | } |