mirror of
https://github.com/nextcloud/passman.git
synced 2024-11-14 11:57:38 +08:00
30 lines
660 B
PHP
30 lines
660 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 {
|
||
|
|
||
|
private $request;
|
||
|
|
||
|
public function __construct(IRequest $request) {
|
||
|
$this->request = $request;
|
||
|
}
|
||
|
|
||
|
public function afterController($controller, $methodName, Response $response) {
|
||
|
if($response instanceof JSONResponse){
|
||
|
$origin = $this->request->server['HTTP_ORIGIN'];
|
||
|
if($origin) {
|
||
|
$response->addHeader('Access-Control-Allow-Origin', $origin);
|
||
|
}
|
||
|
}
|
||
|
return parent::afterController($controller, $methodName, $response);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|