• lumen中间件中设置响应header


    <?php
    
    namespace AppHttpMiddleware;
    
    use Closure;
    
    class BeforeMiddleware
    {
    
        public function handle($request, Closure $next)
        {
            // 执行动作
    
            $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
    
            $allow_origin = array(
                'http://m.c.com',
                'http://www.t.com'
            );
    
            if(in_array($origin, $allow_origin)){
                header('Access-Control-Allow-Origin:'.$origin);
                header('Access-Control-Allow-Headers:Content-Type, Accept, Authorization, X-Requested-With');
                header('Access-Control-Allow-Methods:POST, GET, OPTIONS, PUT, DELETE, PATCH');
            }
    
            return $next($request);
        }
    
    }

    然后bootstrap/app.php中注册该中间件:

    $app->middleware([
        IlluminateSessionMiddlewareStartSession::class,
        AppHttpMiddlewareVerifyCsrfToken::class,
        AppHttpMiddlewareEncryptCookies::class,
        AppHttpMiddlewareBeforeMiddleware::class
    ]);
  • 相关阅读:
    JAVA类与对象(一)----基础概念理解
    JAVA数组
    JAVA算术运算符、关系运算符和位运算符
    JAVA数据类型
    JAVA配置环境变量
    C#中怎么生成36位的GUID
    jqAjax
    二进制1的个数
    成绩转换
    对决
  • 原文地址:https://www.cnblogs.com/dongruiha/p/7063347.html
Copyright © 2020-2023  润新知