StaticFile.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * This file is part of webman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace app\middleware;
  15. use Webman\MiddlewareInterface;
  16. use Webman\Http\Response;
  17. use Webman\Http\Request;
  18. /**
  19. * Class StaticFile
  20. * @package app\middleware
  21. */
  22. class StaticFile implements MiddlewareInterface
  23. {
  24. public function process(Request $request, callable $next): Response
  25. {
  26. // Access to files beginning with. Is prohibited
  27. if (strpos($request->path(), '/.') !== false) {
  28. return response('<h1>403 forbidden</h1>', 403);
  29. }
  30. /** @var Response $response */
  31. $response = $next($request);
  32. // Add cross domain HTTP header
  33. /*$response->withHeaders([
  34. 'Access-Control-Allow-Origin' => '*',
  35. 'Access-Control-Allow-Credentials' => 'true',
  36. ]);*/
  37. return $response;
  38. }
  39. }