All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.houbb.current.user.utils.RequestUtil Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package com.github.houbb.current.user.utils;

import com.github.houbb.heaven.annotation.CommonEager;
import com.github.houbb.heaven.util.lang.StringUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * 请求参数
 * @author binbin.hou
 * @since 0.0.12
 */
@CommonEager
public final class RequestUtil {

    private RequestUtil(){}

    public static String getIp(final HttpServletRequest request) {
        // 获取请求IP地址
        String ip = request.getHeader("X-Forwarded-For");
        if (StringUtil.isEmptyTrim(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (StringUtil.isEmptyTrim(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (StringUtil.isEmptyTrim(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy