Skip to content

Commit f314fe0

Browse files
authored
Merge pull request #3 from activecollab/add-custom-type-header
Add X-Type header
2 parents 6897b5b + d5b6e79 commit f314fe0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Response/FileDownloadResponse.php

+19-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ class FileDownloadResponse implements ResponseInterface
3636
private $filename;
3737

3838
/**
39-
* @param string $file
40-
* @param string $content_type
41-
* @param bool $inline
42-
* @param string $filename
39+
* @var string|null
4340
*/
44-
public function __construct($file, $content_type, $inline = false, $filename = null)
41+
private $x_type;
42+
43+
/**
44+
* @param string $file
45+
* @param string $content_type
46+
* @param bool $inline
47+
* @param string $filename
48+
* @param string|null $x_type
49+
*/
50+
public function __construct($file, $content_type, $inline = false, $filename = null, $x_type = null)
4551
{
4652
if (!is_file($file)) {
4753
throw new RuntimeException('Download file not found');
@@ -51,6 +57,7 @@ public function __construct($file, $content_type, $inline = false, $filename = n
5157
$this->content_type = $content_type;
5258
$this->inline = $inline;
5359
$this->filename = $filename;
60+
$this->x_type = $x_type;
5461
}
5562

5663
/**
@@ -61,14 +68,20 @@ public function getHeaders()
6168
$filename = $this->filename ?: basename($this->file);
6269
$disposition = $this->inline ? 'inline' : 'attachment';
6370

64-
return [
71+
$result = [
6572
'Content-Description' => $this->inline ? 'Binary' : 'File Transfer',
6673
'Content-Type' => $this->inline ? $this->content_type : 'application/octet-stream',
6774
'Content-Length' => filesize($this->file),
6875
'Content-Disposition' => $disposition . ';filename="' . $filename . '"',
6976
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
7077
'Pragma' => 'public',
7178
];
79+
80+
if ($this->x_type) {
81+
$result['X-Type'] = $this->x_type;
82+
}
83+
84+
return $result;
7285
}
7386

7487
public function loadFile()

0 commit comments

Comments
 (0)