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

Add the ability to get the ip address of the client in websocket #8856

Closed
essapp opened this issue Jun 6, 2024 · 4 comments
Closed

Add the ability to get the ip address of the client in websocket #8856

essapp opened this issue Jun 6, 2024 · 4 comments
Assignees
Labels
4.x Version 4.x triage websocket WebSocket in Helidon

Comments

@essapp
Copy link

essapp commented Jun 6, 2024

Environment Details

  • Helidon Version:4.0.9
  • Helidon SE
  • JDK version:21
  • OS:mac
  • Docker version (if applicable):

Problem Description

In actual use, often need to get the ip address of the client, in the websocket server development.

@m0mus m0mus added triage websocket WebSocket in Helidon 4.x Version 4.x labels Jun 24, 2024
@spericas
Copy link
Member

spericas commented Jul 8, 2024

One option would be to make the SocketContext available from the WsSession, and then:

WsSession ws = ...
PeerInfo peer = ws.socketContext().remotePeer();

Are you using the Proxy Protocol in your app?

@essapp
Copy link
Author

essapp commented Jul 10, 2024

One option would be to make the SocketContext available from the WsSession, and then:

WsSession ws = ...
PeerInfo peer = ws.socketContext().remotePeer();

Are you using the Proxy Protocol in your app?

Yes, I might, thanks!

@spericas
Copy link
Member

One option would be to make the SocketContext available from the WsSession, and then:

WsSession ws = ...
PeerInfo peer = ws.socketContext().remotePeer();

Are you using the Proxy Protocol in your app?

Yes, I might, thanks!

If using https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt then there's already support for it (it just needs to be enabled by turning it on the listener) and you get host and port info in the request headers X-Forwarded-For and X-Forwarded-Port (automatically added by Helidon). Note that the proxy protocol preamble is not optional, if enabled, then it must be present. If that's what you need, then it's already in 4.0.9.

@essapp
Copy link
Author

essapp commented Jul 11, 2024

One option would be to make the SocketContext available from the WsSession, and then:

WsSession ws = ...
PeerInfo peer = ws.socketContext().remotePeer();

Are you using the Proxy Protocol in your app?

Yes, I might, thanks!

If using https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt then there's already support for it (it just needs to be enabled by turning it on the listener) and you get host and port info in the request headers X-Forwarded-For and X-Forwarded-Port (automatically added by Helidon). Note that the proxy protocol preamble is not optional, if enabled, then it must be present. If that's what you need, then it's already in 4.0.9.

OK,thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x triage websocket WebSocket in Helidon
Projects
Archived in project
Development

No branches or pull requests

3 participants