package com.sonic.common.context;

import java.util.Optional;

import javax.servlet.http.HttpServletRequest;

/**
 * http请求的context对象. 方便在服务层访问到http request信息.
 * @author code
 */
public class HttpRequestContext {

    private static ThreadLocal<HttpServletRequest> threadLocal = new InheritableThreadLocal<HttpServletRequest>();

    public static void set(HttpServletRequest request) {
        threadLocal.set(request);
    }

    public static Optional<HttpServletRequest> get() {
        return Optional.ofNullable(threadLocal.get());
    }

    public static void remove() {
        threadLocal.remove();
    }
}
