19declare(strict_types=1);
66 public function inline(
85 $r = $this->
http->response();
86 $uri = $stream->getMetadata()[
'uri'];
94 || $uri ===
'php://memory'
95 || $this->isTemporaryFile((
string) $uri)
97 $this->response_builder = $this->fallback_response_builder;
108 $r = $this->response_builder->buildForStream(
109 $this->
http->request(),
113 $this->saveAndClose($r);
118 $real_path = realpath($uri);
119 if ($real_path ===
false) {
122 $temp_dirs = array_filter([
123 defined(
'CLIENT_DATA_DIR') ? realpath(\
CLIENT_DATA_DIR .
'/temp') :
false,
124 realpath(sys_get_temp_dir()),
126 foreach ($temp_dirs as $temp_dir) {
127 if (str_starts_with($real_path, rtrim($temp_dir,
'/') .
'/')) {
136 $r = $this->
http->response();
139 $parts = explode(self::SUBREQUEST_SEPARATOR,
$token);
141 if (count($parts) > 1) {
143 $sub_request = implode(
'/', array_slice($parts, 1));
146 $payload = $this->data_signer->verifyStreamToken(
$token);
150 $host_allowed = $isolated ? $this->isRequestHostAllowed() : !$this->isRequestOnContentHost();
151 if (!$host_allowed) {
157 $uri = $payload->
getUri();
158 $mime_type = $payload->getMimeType();
159 $file_name = $payload->getFilename();
160 $disposition = Disposition::tryFrom($payload->getDisposition()) ?? Disposition::INLINE;
163 $uri = $payload->
getUri();
164 $mime_type = $this->determineMimeType($uri);
165 $file_name = $payload->getFilename();
166 $disposition = Disposition::INLINE;
175 if ($sub_request ===
null) {
176 $r = $this->setGeneralHeaders(
185 $this->
http->saveResponse(
186 $this->response_builder->buildForStream(
187 $this->http->request(),
189 Streams::ofResource(fopen($uri,
'rb'))
193 $requested_zip = $uri;
194 $sub_request = urldecode($sub_request);
196 $sub_request = explode(
'?', $sub_request)[0];
199 $file_inside_ZIP = Streams::ofFileInsideZIP($requested_zip, $sub_request);
200 }
catch (\Throwable) {
203 $file_inside_zip_uri = $file_inside_ZIP->getMetadata()[
'uri'];
204 $file_inside_zip_stream = fopen($file_inside_zip_uri,
'rb');
206 if ($file_inside_zip_stream ===
false) {
211 $this->response_builder = $this->fallback_response_builder;
213 $mime_type = $this->determineMimeType($file_inside_zip_uri);
214 $r = $this->setGeneralHeaders(
216 $file_inside_zip_uri,
218 basename($sub_request),
224 $this->
http->saveResponse(
225 $this->response_builder->buildForStream(
226 $this->http->request(),
232 $this->
http->sendResponse();
233 $this->
http->close();
238 $suffix = strtolower(pathinfo(
$filename, PATHINFO_EXTENSION));
239 if (isset($this->mime_type_map[$suffix])) {
240 if (is_array($this->mime_type_map[$suffix]) && isset($this->mime_type_map[$suffix][0])) {
241 return $this->mime_type_map[$suffix][0];
244 return $this->mime_type_map[$suffix];
247 $mime_type = mime_content_type(
$filename);
248 if ($mime_type ===
'application/octet-stream') {
249 $mime_type = mime_content_type(substr(
$filename, 64));
251 return $mime_type ?:
'application/octet-stream';
const SUBREQUEST_SEPARATOR
deliver(FileStream $stream, string $download_file_name, ?string $mime_type=null, Disposition $disposition=Disposition::INLINE)
__construct(private DataSigning $data_signer, GlobalHttpState $http, ResponseBuilder $response_builder, ResponseBuilder $fallback_response_builder, IsolationConfig $isolation=new IsolationConfig(false, null, null),)
isTemporaryFile(string $uri)
attached(FileStream $stream, string $download_file_name, ?string $mime_type=null)
determineMimeType(string $filename)
deliverFromToken(string $token)
string $download_file_name
Read-only configuration of the IRSS User Content Isolation feature.
isIsolated()
Whether the file is delivered from the content domain when User Content Isolation is active (the defa...
Stream factory which enables the user to create streams without the knowledge of the concrete class.
The base interface for all filesystem streams.
Interface GlobalHttpState.
readonly HttpService $http
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc