Completed
Push — feature/webcal ( 548f3f...3c04d7 )
by Georg
21:22
created

ProxyController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 39
rs 10
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A proxy() 0 13 1
1
<?php
2
/**
3
 * ownCloud - Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2016 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library 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
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\Controller;
23
24
use OCA\Calendar\Http\StreamResponse;
25
26
use OCP\AppFramework\Controller;
27
use OCP\Http\Client\IClientService;
28
use OCP\IRequest;
29
30
class ProxyController extends Controller {
31
32
	/**
33
	 * @var IClientService
34
	 */
35
	protected $client;
36
37
	/**
38
	 * @param string $appName
39
	 * @param IRequest $request an instance of the request
40
	 * @param IClientService $client
41
	 */
42
	public function __construct($appName, IRequest $request,
43
								IClientService $client) {
44
		parent::__construct($appName, $request);
45
		$this->client = $client;
46
	}
47
48
	/**
49
	 * @NoAdminRequired
50
	 * @NoCSRFRequired
51
	 *
52
	 * @param $url
53
	 * @return StreamResponse
54
	 */
55
	public function proxy($url) {
56
		$client = $this->client->newClient();
57
		$clientResponse = $client->get($url, [
58
			'stream' => true,
59
		]);
60
61
		$response = new StreamResponse($clientResponse->getBody());
62
		$response->setHeaders([
63
			'Content-Type' => 'text/calendar',
64
		]);
65
66
		return $response;
67
	}
68
}