From eb9fce2fa5f33d45b3ae5fc3747ae59dc372e599 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 31 Jul 2013 13:41:46 -0700 Subject: [PATCH] JSR-356: fixing Session.getProtocolVersion() --- .../jetty/websocket/api/UpgradeRequest.java | 36 ++++++++++++------- .../websocket/common/WebSocketSession.java | 1 + 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java index 984c3577364..99b532c9ec3 100644 --- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java +++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/UpgradeRequest.java @@ -76,19 +76,6 @@ public class UpgradeRequest extensions.add(ExtensionConfig.parse(config)); } } - - /** - * Get the User Principal for this request. - *

- * Only applicable when using UpgradeRequest from server side. - * - * @return the user principal - */ - public Principal getUserPrincipal() - { - // Server side should override to implement - return null; - } public void clearHeaders() { @@ -201,6 +188,16 @@ public class UpgradeRequest return Collections.unmodifiableMap(parameters); } + public String getProtocolVersion() + { + String version = getHeader("Sec-WebSocket-Version"); + if (version == null) + { + return "13"; + } + return version; + } + public String getQueryString() { return requestURI.getQuery(); @@ -228,6 +225,19 @@ public class UpgradeRequest return subProtocols; } + /** + * Get the User Principal for this request. + *

+ * Only applicable when using UpgradeRequest from server side. + * + * @return the user principal + */ + public Principal getUserPrincipal() + { + // Server side should override to implement + return null; + } + public boolean hasSubProtocol(String test) { for (String protocol : subProtocols) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index ea10562bfdb..c863535019d 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -429,6 +429,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc public void setUpgradeRequest(UpgradeRequest request) { this.upgradeRequest = request; + this.protocolVersion = request.getProtocolVersion(); } public void setUpgradeResponse(UpgradeResponse response)