package com.blade.security.web.cors;

import com.blade.mvc.RouteContext;
import com.blade.mvc.hook.WebHook;

/**
 * CorsMiddleware
 *
 * @author biezhi
 * @date 2018/7/11
 */
public class CorsMiddleware implements WebHook {

    @Override
    public boolean before(RouteContext context) {
        context.header("Access-Control-Allow-Origin", "*");
        context.header("Access-Control-Allow-Credential", "true");
        context.header("Access-Control-Allow-Methods", "GET, OPTIONS, HEAD, PUT, POST, DELETE");
        if ("OPTIONS".equals(context.method())) {
            context.status(202);
        }
        return true;
    }

}

@@ -405,24 +405,177 @@
 %22, %22true%22);%0A
+        context.header(%22Access-Control-Allow-Headers%22, %22Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie, Cache-Control%22);%0A
         cont

improve cors middleware