passman/lib/Middleware/APIMiddleware.php

31 lines
769 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 {
private $request;
public function __construct(IRequest $request) {
$this->request = $request;
}
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);
}
}