ProxyDownloadResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 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