Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-11-05 00:02:50 +0000
committerGreg Wilkins2012-11-05 00:02:50 +0000
commit36ddd3f5d628e2fc2d3a85e293f6f6c0f3593c59 (patch)
tree7b86f99933cf6d92bff074b786872c45a61606be /jetty-websocket
parent13f6940fc3d19ef11ac2b5307fb5282f0d0d901e (diff)
downloadorg.eclipse.jetty.project-36ddd3f5d628e2fc2d3a85e293f6f6c0f3593c59.tar.gz
org.eclipse.jetty.project-36ddd3f5d628e2fc2d3a85e293f6f6c0f3593c59.tar.xz
org.eclipse.jetty.project-36ddd3f5d628e2fc2d3a85e293f6f6c0f3593c59.zip
393368 min websocket version
Diffstat (limited to 'jetty-websocket')
-rw-r--r--jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java2
-rw-r--r--jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketFactory.java35
-rw-r--r--jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServlet.java7
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/SafariWebsocketDraft0Test.java4
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadD08Test.java3
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadRFC6455Test.java2
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD00Test.java1
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD06Test.java1
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java1
-rw-r--r--jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java2
10 files changed, 52 insertions, 6 deletions
diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java
index dd1ba46b8e..a4e10bd32a 100644
--- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java
+++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java
@@ -123,6 +123,8 @@ public class WebSocketConnectionD00 extends AbstractConnection implements WebSoc
_endp.close();
break;
}
+ else if (filled==0)
+ return this;
}
if (_websocket instanceof OnFrame)
diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketFactory.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketFactory.java
index eca24b73e8..ae01166ed9 100644
--- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketFactory.java
+++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketFactory.java
@@ -81,16 +81,37 @@ public class WebSocketFactory extends AbstractLifeCycle
private int _maxIdleTime = 300000;
private int _maxTextMessageSize = 16 * 1024;
private int _maxBinaryMessageSize = -1;
+ private int _minVersion;
public WebSocketFactory(Acceptor acceptor)
{
- this(acceptor, 64 * 1024);
+ this(acceptor, 64 * 1024, WebSocketConnectionRFC6455.VERSION);
}
public WebSocketFactory(Acceptor acceptor, int bufferSize)
{
+ this(acceptor, bufferSize, WebSocketConnectionRFC6455.VERSION);
+ }
+
+ public WebSocketFactory(Acceptor acceptor, int bufferSize, int minVersion)
+ {
_buffers = new WebSocketBuffers(bufferSize);
_acceptor = acceptor;
+ _minVersion=WebSocketConnectionRFC6455.VERSION;
+ }
+
+ public int getMinVersion()
+ {
+ return _minVersion;
+ }
+
+ /* ------------------------------------------------------------ */
+ /**
+ * @param minVersion The minimum support version (default RCF6455.VERSION == 13 )
+ */
+ public void setMinVersion(int minVersion)
+ {
+ _minVersion = minVersion;
}
/**
@@ -227,6 +248,8 @@ public class WebSocketFactory extends AbstractLifeCycle
}
final WebSocketServletConnection connection;
+ if (draft<_minVersion)
+ draft=Integer.MAX_VALUE;
switch (draft)
{
case -1: // unspecified draft/version
@@ -263,7 +286,15 @@ public class WebSocketFactory extends AbstractLifeCycle
LOG.warn("Unsupported Websocket version: " + draft);
// Per RFC 6455 - 4.4 - Supporting Multiple Versions of WebSocket Protocol
// Using the examples as outlined
- response.setHeader("Sec-WebSocket-Version", "13, 8, 6, 0");
+ String versions="13";
+ if (_minVersion<=8)
+ versions+=", 8";
+ if (_minVersion<=6)
+ versions+=", 6";
+ if (_minVersion<=0)
+ versions+=", 0";
+
+ response.setHeader("Sec-WebSocket-Version", versions);
throw new HttpException(400, "Unsupported websocket version specification: " + draft);
}
}
diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServlet.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServlet.java
index 3990ce4ddf..d52c801900 100644
--- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServlet.java
+++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServlet.java
@@ -45,6 +45,9 @@ import org.eclipse.jetty.util.log.Logger;
* <p/>
* The initParameter "maxBinaryMessagesSize" can be used to set the size in bytes
* that a websocket may be accept before closing.
+ * <p/>
+ * The initParameter "minVersion" can be used to set the minimum protocol version
+ * accepted. Default is the RFC6455 version (13)
*/
@SuppressWarnings("serial")
public abstract class WebSocketServlet extends HttpServlet implements WebSocketFactory.Acceptor
@@ -76,6 +79,10 @@ public abstract class WebSocketServlet extends HttpServlet implements WebSocketF
max = getInitParameter("maxBinaryMessageSize");
if (max != null)
_webSocketFactory.setMaxBinaryMessageSize(Integer.parseInt(max));
+
+ String min = getInitParameter("minVersion");
+ if (min != null)
+ _webSocketFactory.setMinVersion(Integer.parseInt(min));
}
catch (ServletException x)
{
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/SafariWebsocketDraft0Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/SafariWebsocketDraft0Test.java
index 5e59f32dcb..6706350149 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/SafariWebsocketDraft0Test.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/SafariWebsocketDraft0Test.java
@@ -62,7 +62,9 @@ public class SafariWebsocketDraft0Test
// Serve capture servlet
servlet = new WebSocketCaptureServlet();
- context.addServlet(new ServletHolder(servlet),"/");
+ ServletHolder holder = new ServletHolder(servlet);
+ holder.setInitParameter("minVersion","-1");
+ context.addServlet(holder,"/");
// Start Server
server.start();
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadD08Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadD08Test.java
index d61b1ec666..62500c4548 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadD08Test.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadD08Test.java
@@ -72,6 +72,7 @@ public class WebSocketLoadD08Test
return new EchoWebSocket();
}
};
+ wsHandler.getWebSocketFactory().setMinVersion(8);
wsHandler.setHandler(new DefaultHandler());
_server.setHandler(wsHandler);
@@ -196,7 +197,7 @@ public class WebSocketLoadD08Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
- "Sec-WebSocket-Version: 7\r\n"+
+ "Sec-WebSocket-Version: 8\r\n"+
"\r\n");
output.flush();
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadRFC6455Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadRFC6455Test.java
index d119a13db0..514ce75412 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadRFC6455Test.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketLoadRFC6455Test.java
@@ -194,7 +194,7 @@ public class WebSocketLoadRFC6455Test
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
- "Sec-WebSocket-Version: 7\r\n"+
+ "Sec-WebSocket-Version: 13\r\n"+
"\r\n");
output.flush();
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD00Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD00Test.java
index f3ab2e71c6..1042978974 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD00Test.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD00Test.java
@@ -80,6 +80,7 @@ public class WebSocketMessageD00Test
return __serverWebSocket;
}
};
+ wsHandler.getWebSocketFactory().setMinVersion(-1);
wsHandler.setHandler(new DefaultHandler());
__server.setHandler(wsHandler);
__server.start();
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD06Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD06Test.java
index 45f7791f72..2ce05d1c92 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD06Test.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD06Test.java
@@ -66,6 +66,7 @@ public class WebSocketMessageD06Test
return _serverWebSocket;
}
};
+ wsHandler.getWebSocketFactory().setMinVersion(6);
wsHandler.getWebSocketFactory().setBufferSize(8192);
wsHandler.getWebSocketFactory().setMaxIdleTime(1000);
wsHandler.setHandler(new DefaultHandler());
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java
index e43e30deb2..971f26f479 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketMessageD08Test.java
@@ -77,6 +77,7 @@ public class WebSocketMessageD08Test
return __serverWebSocket;
}
};
+ wsHandler.getWebSocketFactory().setMinVersion(8);
wsHandler.getWebSocketFactory().setBufferSize(8192);
wsHandler.getWebSocketFactory().setMaxIdleTime(1000);
wsHandler.setHandler(new DefaultHandler());
diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java
index 8296b1a9b2..f03aba618b 100644
--- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java
+++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketServletRFCTest.java
@@ -180,7 +180,7 @@ public class WebSocketServletRFCTest
// System.out.println("RESPONSE: " + respHeader);
Assert.assertThat("Response Code",respHeader,startsWith("HTTP/1.1 400 Unsupported websocket version specification"));
- Assert.assertThat("Response Header Versions",respHeader,containsString("Sec-WebSocket-Version: 13, 8, 6, 0\r\n"));
+ Assert.assertThat("Response Header Versions",respHeader,containsString("Sec-WebSocket-Version: 13\r\n"));
}
finally
{

Back to the top