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

com.yuweix.kuafu.core.reactive.ActionUtil Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.yuweix.kuafu.core.reactive;


import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;


/**
 * @author yuwei
 */
public abstract class ActionUtil {
	/**
	 * 获得客户端IP
	 * @return
	 */
	public static String getRequestIP(ServerHttpRequest request) {
		HttpHeaders headers = request.getHeaders();

		String ip = headers.getFirst("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = headers.getFirst("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = headers.getFirst("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = headers.getFirst("X-Real-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddress().toString();
		}

		if (ip == null) {
			return null;
		}
		return ip.split(",")[0];
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy