package com.firefly.example.reactive.coffee.store.router.impl.sys;

import com.firefly.annotation.Component;
import com.firefly.annotation.Inject;
import com.firefly.codec.http2.model.HttpHeader;
import com.firefly.example.reactive.coffee.store.router.RouterInstaller;
import com.firefly.server.http2.HTTP2ServerBuilder;
import com.firefly.server.http2.router.handler.file.StaticFileHandler;
import com.firefly.utils.log.slf4j.ext.LazyLogger;

import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author Pengtao Qiu
 */
@Component("sysRouterInstaller")
public class SysRouterInstaller implements RouterInstaller {

    private static final LazyLogger logger = LazyLogger.create();

    @Inject
    private HTTP2ServerBuilder server;

    @Inject
    private GlobalHandler globalHandler;

    @Inject
    private TransactionalHandler transactionalHandler;

    @Override
    public void install() {
        // global handler
        server.router().path("*").handler(globalHandler);

        // HTTP transaction manager
        server.router().methods(transactionalHandler.getMethods()).handler(transactionalHandler);

        // static file
        try {
            Path path = Paths.get(SysRouterInstaller.class.getResource("/").toURI());
            StaticFileHandler staticFileHandler = new StaticFileHandler(path.toAbsolutePath().toString());
            server.router().get("/static/*").handler(ctx -> {
                ctx.put(HttpHeader.CACHE_CONTROL, "max-age=86400");
                staticFileHandler.handle(ctx);
            });
        } catch (URISyntaxException e) {
            logger.error(() -> "setup static file router exception", e);
        }
    }

    @Override
    public Integer order() {
        return 0;
    }
}

@@ -381,24 +381,185 @@
 ileHandler;%0A
+import com.firefly.server.http2.router.handler.session.HTTPSessionConfiguration;%0Aimport com.firefly.server.http2.router.handler.session.LocalHTTPSessionHandler;%0A
 import com.f
@@ -1176,32 +1176,162 @@
 lobalHandler);%0A%0A
+        // local session%0A        server.router().path(%22*%22).handler(new LocalHTTPSessionHandler(new HTTPSessionConfiguration()));%0A%0A
         // HTTP 

add local session