class SessionHandler {

    private final Class<? extends Session> sessionType;
    private final SessionManager sessionManager;
    private int timeout;
    private String sessionKey;

    public SessionHandler(Blade blade) {
        this.sessionType = blade.httpOptions().getSessionType();
        this.sessionManager = blade.sessionManager();

        this.initOptions(blade.httpOptions(), blade.environment());
    }

    public Session createSession(Request request) {
        Session session = getSession(request);

        long now = Instant.now().getEpochSecond();
        if (null == session) {
            long expired = now + timeout;
            session = ReflectKit.newInstance(sessionType);
            if (null == session) {
                throw new InternalErrorException("Unable to create session object :(");
            }
            session.id(UUID.UU32());
            session.created(now);
            session.expired(expired);
            sessionManager.createSession(session);
            return session;
        } else {
            if (session.expired() < now) {
                sessionManager.destroySession(session);
            } else {
                // renewal
                long expired = now + timeout;
                session.expired(expired);
            }
        }
        return session;
    }

    private Session getSession(Request request) {<FILL_FUNCTION_BODY>}

    private void initOptions(HttpOptions httpOptions, Environment environment) {
        this.timeout = httpOptions.getSessionTimeout();
        this.sessionKey = httpOptions.getSessionKey();
        if (this.timeout != HttpOptions.DEFAULT_SESSION_TIMEOUT) {
            environment.set(ENV_KEY_SESSION_TIMEOUT, this.timeout);
        } else {
            this.timeout = environment.getInt(ENV_KEY_SESSION_TIMEOUT, HttpOptions.DEFAULT_SESSION_TIMEOUT);
            httpOptions.setSessionTimeout(this.timeout);
        }

        if (!HttpOptions.DEFAULT_SESSION_KEY.equals(this.sessionKey)) {
            environment.set(ENV_KEY_SESSION_KEY, this.sessionKey);
        } else {
            this.sessionKey = environment.get(ENV_KEY_SESSION_KEY, HttpOptions.DEFAULT_SESSION_KEY);
            httpOptions.setSessionKey(this.sessionKey);
        }
    }

}

        String cookieHeader = request.cookie(this.sessionKey);
        if (StringKit.isEmpty(cookieHeader)) {
            return null;
        }
        return sessionManager.getSession(cookieHeader);
    
<no_super_class>