@@ -36,12 +36,18 @@ class FileDownloadResponse implements ResponseInterface
36
36
private $ filename ;
37
37
38
38
/**
39
- * @param string $file
40
- * @param string $content_type
41
- * @param bool $inline
42
- * @param string $filename
39
+ * @var string|null
43
40
*/
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 )
45
51
{
46
52
if (!is_file ($ file )) {
47
53
throw new RuntimeException ('Download file not found ' );
@@ -51,6 +57,7 @@ public function __construct($file, $content_type, $inline = false, $filename = n
51
57
$ this ->content_type = $ content_type ;
52
58
$ this ->inline = $ inline ;
53
59
$ this ->filename = $ filename ;
60
+ $ this ->x_type = $ x_type ;
54
61
}
55
62
56
63
/**
@@ -61,14 +68,20 @@ public function getHeaders()
61
68
$ filename = $ this ->filename ?: basename ($ this ->file );
62
69
$ disposition = $ this ->inline ? 'inline ' : 'attachment ' ;
63
70
64
- return [
71
+ $ result = [
65
72
'Content-Description ' => $ this ->inline ? 'Binary ' : 'File Transfer ' ,
66
73
'Content-Type ' => $ this ->inline ? $ this ->content_type : 'application/octet-stream ' ,
67
74
'Content-Length ' => filesize ($ this ->file ),
68
75
'Content-Disposition ' => $ disposition . ';filename=" ' . $ filename . '" ' ,
69
76
'Cache-Control ' => 'must-revalidate, post-check=0, pre-check=0 ' ,
70
77
'Pragma ' => 'public ' ,
71
78
];
79
+
80
+ if ($ this ->x_type ) {
81
+ $ result ['X-Type ' ] = $ this ->x_type ;
82
+ }
83
+
84
+ return $ result ;
72
85
}
73
86
74
87
public function loadFile ()
0 commit comments