Skip to content
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

Merged
merged 19 commits into from
Aug 10, 2024
Merged

Conversation

ajaypj
Copy link
Collaborator

@ajaypj ajaypj commented Aug 7, 2024

No description provided.

String ipAddressString = attributes.get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString();
if (StringUtils.isNotEmpty(ipAddressString)){
if (ipAddressString.startsWith("/")){
ipAddressString = ipAddressString.split("/", 2)[1];
Copy link
Member

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.

Copy link
Collaborator Author

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.

@ajaypj ajaypj changed the title added custom accesslog filter get client ip Aug 8, 2024
Comment on lines 13 to 24
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));
}
Copy link
Member

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.

@kingster kingster changed the title get client ip GRPC getClientIP - Strip and keep only ip-address Aug 9, 2024
kingster and others added 8 commits August 9, 2024 17:26
* master:
  Allow mutation in HttpFilters (#87)
  Add additional fields to access-log context (#93)
  Fix `ApplicationHeaders.getHeaders()` (#92)
  Fix getRequestURI in Access Log (#90)
…xpress into custom-access

* 'custom-access' of github.com:flipkart-incubator/grpc-jexpress:
  Fix Filter Lifecycle  (#94)
@kingster kingster merged commit f0b42e5 into master Aug 10, 2024
3 checks passed
@kingster kingster deleted the custom-access branch August 10, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants