Files

44 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2022-08-19 19:48:37 +08:00
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace app\index\middleware;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;
/**
* Class StaticFile
* @package app\middleware
*/
class StaticFile implements MiddlewareInterface
{
2022-11-28 19:11:12 +08:00
public function process(Request $request, callable $handler): Response
2022-08-19 19:48:37 +08:00
{
// Access to files beginning with. Is prohibited
2022-11-28 19:11:12 +08:00
if (str_contains($request->path(), '/.')) {
2022-08-19 19:48:37 +08:00
return response('<h1>403 forbidden</h1>', 403);
}
2022-11-28 19:11:12 +08:00
2022-08-19 19:48:37 +08:00
/** @var Response $response */
2022-11-28 19:11:12 +08:00
$response = $handler($request);
2022-08-19 19:48:37 +08:00
// Add cross domain HTTP header
/*$response->withHeaders([
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Credentials' => 'true',
]);*/
return $response;
}
}