package org.ta.pddserver.utils;

import jakarta.servlet.http.HttpServletRequest;

public class HttpRequestHandlerTool {

    private static String getClientIP(HttpServletRequest request) {

        String xForwardedFor = request.getHeader("X-Forwarded-For");
        if (xForwardedFor != null && !xForwardedFor.isEmpty()) {

            return xForwardedFor.split(",")[0].trim();
        }

        String xRealIP = request.getHeader("X-Real-IP");
        if (xRealIP != null && !xRealIP.isEmpty()) {

            return xRealIP;
        }

        return request.getRemoteAddr();
    }
}
