Completed
Push — feature/webcal ( 7e34f4...548f3f )
by Georg
18:46
created

WebCalController   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 OC\AppFramework\Http;
25
use OCA\Calendar\Http\StreamResponse;
26
use OCP\AppFramework\Controller;
27
use OCP\AppFramework\Http\ContentSecurityPolicy;
28
use OCP\AppFramework\Http\DataDisplayResponse;
29
use OCP\AppFramework\Http\NotFoundResponse;
30
use OCP\AppFramework\Http\TemplateResponse;
31
use OCP\IConfig;
32
use OCP\IRequest;
33
use OCP\IUserSession;
34
35
use \OCP\Http\Client\IClientService;
36
37
class WebCalController extends Controller {
38
39
	/**
40
	 * @var IClientService
41
	 */
42
	protected $client;
43
44
	/**
45
	 * @param string $appName
46
	 * @param IRequest $request an instance of the request
47
	 * @param IClientService $client
48
	 */
49
	public function __construct($appName, IRequest $request,
50
								IClientService $client) {
51
		parent::__construct($appName, $request);
52
		$this->client = $client;
53
	}
54
55
	/**
56
	 * @NoAdminRequired
57
	 * @NoCSRFRequired
58
	 *
59
	 * @param $url
60
	 * @return StreamResponse
61
	 */
62
	public function proxy($url) {
63
		$client = $this->client->newClient();
64
		$clientResponse = $client->get($url, [
65
			'stream' => true,
66
		]);
67
68
		$response = new StreamResponse($clientResponse->getBody());
69
		$response->setHeaders([
70
			'Content-Type' => 'text/calendar',
71
		]);
72
73
		return $response;
74
	}
75
}