/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.webapi.common;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 请求工具类
 *
 * @author lingee
 * @date 2023/8/2
 */
public class RequestUtil {

    /**
     * 获取请求
     *
     * @return servlet请求
     */
    public static HttpServletRequest getRequest() {
        RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
        if (attrs == null) {
            return null;
        }
        final ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) attrs;
        return servletRequestAttributes.getRequest();
    }
}
