-
Notifications
You must be signed in to change notification settings - Fork 17
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
GRPC getClientIP - Strip and keep only ip-address #85
Conversation
String ipAddressString = attributes.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString(); | ||
if (StringUtils.isNotEmpty(ipAddressString)){ | ||
if (ipAddressString.startsWith("/")){ | ||
ipAddressString = ipAddressString.split("/", 2)[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why split here? you can simply skip the first character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ip starts with "/"
did not find why it is starting like this or whether it will always start with "/"
so used split.
guice/src/main/java/com/flipkart/gjex/grpc/interceptor/FilterInterceptor.java
Outdated
Show resolved
Hide resolved
guice/src/main/java/com/flipkart/gjex/grpc/interceptor/FilterInterceptor.java
Outdated
Show resolved
Hide resolved
public void getClientIpTest(){ | ||
InetSocketAddress inetSocketAddress = new InetSocketAddress(IP_ADDRESS, 1234); | ||
Assert.assertEquals(IP_ADDRESS, FilterInterceptor.getClientIp(inetSocketAddress)); | ||
|
||
SocketAddress socketAddress = new SocketAddress() { | ||
@Override | ||
public String toString() { | ||
return IP_ADDRESS; | ||
} | ||
}; | ||
Assert.assertEquals(IP_ADDRESS, FilterInterceptor.getClientIp(socketAddress)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't handle the default scenario itself.
…xpress into custom-access * 'custom-access' of github.com:flipkart-incubator/grpc-jexpress: Fix Filter Lifecycle (#94)
No description provided.