19declare(strict_types=1);
24use Psr\Http\Message\ResponseInterface;
55 private function notFound(ResponseInterface $r): void
57 $this->
http->saveResponse($r->withStatus(404));
58 $this->
http->sendResponse();
75 public function inline(
94 $r = $this->
http->response();
95 $uri = $stream->getMetadata()[
'uri'];
97 if ($stream instanceof
ZIPStream || $stream->getMetadata()[
'uri'] ===
'php://memory') {
98 $this->response_builder = $this->fallback_response_builder;
109 $r = $this->response_builder->buildForStream(
110 $this->
http->request(),
114 $this->saveAndClose($r);
124 $sub_request = implode(
'/', array_slice(
$parts, 1));
127 $r = $this->
http->response();
133 $mime_type =
$payload->getMimeType();
134 $file_name =
$payload->getFilename();
135 $disposition = Disposition::tryFrom(
$payload->getDisposition()) ?? Disposition::INLINE;
139 $mime_type = $this->determineMimeType($uri);
140 $file_name =
$payload->getFilename();
141 $disposition = Disposition::INLINE;
150 if ($sub_request ===
null) {
151 $r = $this->setGeneralHeaders(
159 $this->
http->saveResponse(
160 $this->response_builder->buildForStream(
161 $this->http->request(),
163 Streams::ofResource(fopen($uri,
'rb'))
167 $requested_zip = $uri;
168 $sub_request = urldecode($sub_request);
170 $sub_request = explode(
'?', $sub_request)[0];
173 $file_inside_ZIP = Streams::ofFileInsideZIP($requested_zip, $sub_request);
174 }
catch (\Throwable) {
177 $file_inside_zip_uri = $file_inside_ZIP->getMetadata()[
'uri'];
178 $file_inside_zip_stream = fopen($file_inside_zip_uri,
'rb');
180 if ($file_inside_zip_stream ===
false) {
185 $this->response_builder = $this->fallback_response_builder;
187 $mime_type = $this->determineMimeType($file_inside_zip_uri);
188 $r = $this->setGeneralHeaders(
190 $file_inside_zip_uri,
192 basename($sub_request),
197 $this->
http->saveResponse(
198 $this->response_builder->buildForStream(
199 $this->http->request(),
205 $this->
http->sendResponse();
206 $this->
http->close();
211 $suffix = strtolower(pathinfo(
$filename, PATHINFO_EXTENSION));
212 if (isset($this->mime_type_map[$suffix])) {
213 if (is_array($this->mime_type_map[$suffix]) && isset($this->mime_type_map[$suffix][0])) {
214 return $this->mime_type_map[$suffix][0];
217 return $this->mime_type_map[$suffix];
220 $mime_type = mime_content_type(
$filename);
221 if ($mime_type ===
'application/octet-stream') {
222 $mime_type = mime_content_type(substr(
$filename, 64));
224 return $mime_type ?:
'application/octet-stream';
const SUBREQUEST_SEPARATOR
__construct(private DataSigner $data_signer, Services $http, ResponseBuilder $response_builder, ResponseBuilder $fallback_response_builder,)
deliver(FileStream $stream, string $download_file_name, ?string $mime_type=null, Disposition $disposition=Disposition::INLINE)
notFound(ResponseInterface $r)
attached(FileStream $stream, string $download_file_name, ?string $mime_type=null)
determineMimeType(string $filename)
deliverFromToken(string $token)
string $download_file_name
Stream factory which enables the user to create streams without the knowledge of the concrete class.
The base interface for all filesystem streams.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
if(count($parts) !=3) $payload
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc