-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to override Request.getClientIp() ? #575
Comments
The |
Also see #64. |
@mhagnumdw Any resolution here? Do you see a way to improve the current API (to be easy to config and extend)? |
From what I understood from #95, the idea was to override |
My workaround in my application is to have an abstract implementation of For example, to retrieve the client's IP, I have the helpers below and I use them in my abstract classes: public static String getClientIp(RouteContext routeContext) {
return getClientIp(routeContext.getRequest());
}
public static String getClientIp(Request request) {
String headerXForwardForHeader = StringUtils.defaultString(request.getHeader("X-Forwarded-For"));
String headerXForwardFor0 = headerXForwardForHeader.split(",")[0];
String defaultRemoteAddr = request.getClientIp();
return StringUtils.firstNonBlank(headerXForwardFor0, defaultRemoteAddr);
} |
With what I said above it is possible to get the client IP from two points: provided by Pippo in Depending on the infra, they can bring different results. It would be good if the developer has a single point to get the client's IP. Here we are talking about client IP, but there may be other situations/scenarios. Anyway, there is a workaround and I have no problem using it. |
In my current scenario I need to retrieve the client's IP from the
X-Forwarded-For
header.I could override the
Application.createRequestResponseFactory()
method, create my custom RequestResponseFactory and in it create my instance that inherits from the Request class, overriding thegetClientIp()
method, but theRequest
class is final.The text was updated successfully, but these errors were encountered: