19declare(strict_types=1);
26use Psr\Http\Message\ResponseInterface;
34 protected const MIME_TYPE_MAP = __DIR__ .
'/../../../FileUpload/src/mime_type_map.php';
44 if (is_readable(self::MIME_TYPE_MAP)) {
47 $this->mime_type_map = $map ?? [];
57 if (!$this->isolation->isActivated()) {
61 $expected = $this->isolation->getContentHost();
62 if ($expected ===
null) {
66 return strcasecmp($this->
http->request()->getUri()->getHost(), $expected) === 0;
77 if (!$this->isolation->isActivated()) {
81 $content_host = $this->isolation->getContentHost();
82 if ($content_host ===
null) {
86 return strcasecmp($this->
http->request()->getUri()->getHost(), $content_host) === 0;
94 protected function notFound(ResponseInterface $r): never
96 $this->
http->saveResponse($r->withStatus(404));
97 $this->
http->sendResponse();
102 ResponseInterface $r,
103 ?
string $path_to_delete =
null
105 if ($path_to_delete !== null && file_exists($path_to_delete)) {
108 ignore_user_abort(
true);
110 register_shutdown_function(
static function () use ($path_to_delete):
void {
111 if (file_exists($path_to_delete)) {
112 unlink($path_to_delete);
117 $this->
http->saveResponse($r);
118 $this->
http->sendResponse();
119 $this->
http->close();
123 ResponseInterface $r,
128 bool $isolated =
true
129 ): ResponseInterface {
130 $r = $r->withHeader(
'X-ILIAS-FileDelivery-Method', $this->response_builder->getName());
139 date(
"D, j M Y H:i:s", strtotime(
'+5 days')) .
" GMT"
143 return $isolated ? $this->applyIsolationHeaders($r) : $r;
155 if (!$this->isolation->isActivated()) {
159 $r = $r->withHeader(ResponseHeader::X_CONTENT_TYPE_OPTIONS,
'nosniff');
160 $r = $r->withHeader(
'Cross-Origin-Resource-Policy',
'cross-origin');
161 $r = $r->withHeader(
'Referrer-Policy',
'no-referrer');
163 if (($ilias_domain = $this->isolation->getIliasDomain()) !==
null) {
164 $r = $r->withHeader(ResponseHeader::ACCESS_CONTROL_ALLOW_ORIGIN, $ilias_domain);
165 $r = $r->withAddedHeader(
'Vary',
'Origin');
isRequestOnContentHost()
Inverse of {.
saveAndClose(ResponseInterface $r, ?string $path_to_delete=null)
setGeneralHeaders(ResponseInterface $r, string $uri, string $mime_type, string $file_name, Disposition $disposition=Disposition::INLINE, bool $isolated=true)
applyIsolationHeaders(ResponseInterface $r)
When isolation is active, harden delivery responses:
isRequestHostAllowed()
When user content isolation is active, only requests targeting the configured content domain may be s...
notFound(ResponseInterface $r)
Send an empty 404 response and terminate.
__construct(protected GlobalHttpState $http, protected ResponseBuilder $response_builder, protected ResponseBuilder $fallback_response_builder, protected IsolationConfig $isolation=new IsolationConfig(false, null, null),)
Read-only configuration of the IRSS User Content Isolation feature.
Interface GlobalHttpState.
readonly HttpService $http
static http()
Fetches the global http state from ILIAS.
if(!file_exists('../ilias.ini.php'))