ProxyDownloadResponse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A render() 0 3 1
1
<?php
2
3
/**
4
 * @author Lukas Reschke <[email protected]>
5
 * @author Thomas Müller <[email protected]>
6
 *
7
 * Mail
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 OCA\Mail\Http;
24
25
use OCP\AppFramework\Http\DownloadResponse;
26
27
class ProxyDownloadResponse extends DownloadResponse {
28
29
	private $content;
30
31
	/**
32
	 * Creates a response that prompts the user to download a file which
33
	 * contains the passed string
34
	 * Additionally the response will be cacheable by browsers. Since the content is
35
	 * generally not sensitive content (e.g. Logos in mails) this should not be a problem.
36
	 * @param string $content the content that should be written into the file
37
	 * @param string $filename the name that the downloaded file should have
38
	 * @param string $contentType the mimetype that the downloaded file should have
39
	 */
40 1
	public function __construct($content, $filename, $contentType){
41 1
		parent::__construct($filename, $contentType);
42 1
		$this->content = $content;
43
44 1
		$expires = new \DateTime('now + 11 months');
45 1
		$this->addHeader('Expires', $expires->format(\DateTime::RFC1123));
46 1
		$this->addHeader('Cache-Control', 'private');
47 1
		$this->addHeader('Pragma', 'cache');
48 1
	}
49
50
	/**
51
	 * Simply sets the headers and returns the file contents
52
	 * @return string the file contents
53
	 */
54 1
	public function render(){
55 1
		return $this->content;
56
	}
57
58
}
59