passman/lib/Middleware/APIMiddleware.php

30 lines
734 B
PHP
Raw Normal View History

2017-01-19 20:39:01 +08:00
<?php
namespace OCA\Passman\Middleware;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
2023-06-16 02:40:05 +08:00
use OCP\AppFramework\Middleware;
2017-01-19 20:39:01 +08:00
use OCP\IRequest;
class APIMiddleware extends Middleware {
public function __construct(
private IRequest $request,
) {
2017-01-19 20:39:01 +08:00
}
public function afterController($controller, $methodName, Response $response) {
if($response instanceof JSONResponse){
2017-01-19 20:58:34 +08:00
if(isset($this->request->server['HTTP_ORIGIN'])) {
$response->addHeader('Access-Control-Allow-Origin', $this->request->server['HTTP_ORIGIN']);
2023-06-16 02:40:05 +08:00
} else {
$response->addHeader('Access-Control-Allow-Origin', '*');
}
2017-01-19 20:39:01 +08:00
}
return parent::afterController($controller, $methodName, $response);
}
}