passman/lib/Middleware/APIMiddleware.php
Hamid Dehnavi 9fd9045455 use PHP8's constructor property promotion
Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
2023-07-05 14:40:34 +03:30

29 lines
734 B
PHP

<?php
namespace OCA\Passman\Middleware;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\IRequest;
class APIMiddleware extends Middleware {
public function __construct(
private IRequest $request,
) {
}
public function afterController($controller, $methodName, Response $response) {
if($response instanceof JSONResponse){
if(isset($this->request->server['HTTP_ORIGIN'])) {
$response->addHeader('Access-Control-Allow-Origin', $this->request->server['HTTP_ORIGIN']);
} else {
$response->addHeader('Access-Control-Allow-Origin', '*');
}
}
return parent::afterController($controller, $methodName, $response);
}
}