This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 86cf5d45dd Add new methods to HandshakeRequest 86cf5d45dd is described below commit 86cf5d45dd16910a9f171ca7681763b44d03f817 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Jun 25 08:22:35 2025 +0100 Add new methods to HandshakeRequest --- .../jakarta/websocket/server/HandshakeRequest.java | 76 ++++++++++++++++++++++ .../websocket/server/WsHandshakeRequest.java | 36 ++++++++++ webapps/docs/changelog.xml | 5 ++ 3 files changed, 117 insertions(+) diff --git a/java/jakarta/websocket/server/HandshakeRequest.java b/java/jakarta/websocket/server/HandshakeRequest.java index 1840122228..e876cebd57 100644 --- a/java/jakarta/websocket/server/HandshakeRequest.java +++ b/java/jakarta/websocket/server/HandshakeRequest.java @@ -20,6 +20,7 @@ import java.net.URI; import java.security.Principal; import java.security.cert.X509Certificate; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -63,4 +64,79 @@ public interface HandshakeRequest { * @since WebSocket 2.3 */ X509Certificate[] getUserX509CertificateChain(); + + /** + * Returns the address of the interface on which the WebSocket handshake request was received. The representation is + * determined by the underlying connection features of the WebSocket implementation. It is not safe to assume that + * it will always be an IP address (either IPv4 or IPv6). It could be some other connection representation such as a + * Unix Socket. + * + * @return the address of the interface on which the WebSocket handshake request was received + * + * @since WebSocket 2.3 + */ + String getLocalAddress(); + + /** + * Returns the host name associated with the interface on which the WebSocket handshake request was received. + * + * @return the host name associated with the interface on which the WebSocket handshake request was received. + * + * @since WebSocket 2.3 + */ + String getLocalHostName(); + + /** + * Returns the Internet Protocol (IP) port number of the interface on which the WebSocket handshake request was + * received. If the request was not received via an IP connection, -1 will be returned. + * + * @return the Internet Protocol (IP) port number of the interface on which the WebSocket handshake request was + * received or -1 if not applicable + * + * @since WebSocket 2.3 + */ + int getLocalPort(); + + /** + * Returns the address of the interface of the client or last proxy which sent the WebSocket handshake request. The + * representation is determined by the underlying connection features of the WebSocket implementation. It is not + * safe to assume that it will always be an IP address (either IPv4 or IPv6). It could be some other connection + * representation such as a Unix Socket. + * + * @return the address of the interface of the client or last proxy which sent the WebSocket handshake request + * + * @since WebSocket 2.3 + */ + String getRemoteAddress(); + + /** + * Returns the host name associated with the client or last proxy which sent the WebSocket handshake request. + * + * @return the host name associated with the client or last proxy which sent the WebSocket handshake request. + * + * @since WebSocket 2.3 + */ + String getRemoteHostName(); + + /** + * Returns the Internet Protocol (IP) port number of the interface of the client or last proxy which sent the + * WebSocket handshake request. If the request was not sent via an IP connection, -1 will be returned. + * + * @return the Internet Protocol (IP) port number of the interface of the client or last proxy which sent the + * WebSocket handshake request or -1 if not applicable + * + * @since WebSocket 2.3 + */ + int getRemotePort(); + + /** + * Returns the preferred <code>Locale</code> that the client will accept content in, based on the Accept-Language + * header. If the WebSocket handshake request doesn't provide an Accept-Language header, this method returns the + * default locale for the server. + * + * @return the preferred <code>Locale</code> for the client + * + * @since WebSocket 2.3 + */ + Locale getPreferredLocale(); } diff --git a/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java b/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java index fe2a7b49cd..b910ed3a5b 100644 --- a/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java +++ b/java/org/apache/tomcat/websocket/server/WsHandshakeRequest.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -183,4 +184,39 @@ public class WsHandshakeRequest implements HandshakeRequest { public X509Certificate[] getUserX509CertificateChain() { return (X509Certificate[]) request.getAttribute(Constants.CERTIFICATE_SERVLET_REQUEST_ATTRIBUTE); } + + @Override + public String getLocalAddress() { + return request.getLocalAddr(); + } + + @Override + public String getLocalHostName() { + return request.getLocalName(); + } + + @Override + public int getLocalPort() { + return request.getLocalPort(); + } + + @Override + public String getRemoteAddress() { + return request.getRemoteAddr(); + } + + @Override + public String getRemoteHostName() { + return request.getRemoteHost(); + } + + @Override + public int getRemotePort() { + return request.getRemotePort(); + } + + @Override + public Locale getPreferredLocale() { + return request.getLocale(); + } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index c5b998df1c..ccb340355e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -281,6 +281,11 @@ called after every WebSocket handshake regardless of whether the handshake is successful or not. (markt) </fix> + <add> + Implement the new <code>HandshakeRequest</code> methods that expose the + client's preferred local and the local and remote host name, address and + port information. (markt) + </add> <!-- Entries for backport and removal before 12.0.0-M1 below this line --> </changelog> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org