Filter WebSocket extensions
Before this change the DefaultHandshakeHandler by default passed the list of requested WebSocket extensions as-is relying on the WebSocket engine to remove those not supported. This change ensures that WebSocket extensions not supported by the runtime are proactively removed instead. This change is preparation for SPR-11094.
This commit is contained in:
@@ -60,7 +60,7 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
|
||||
|
||||
this.handshakeHandler.setSupportedProtocols("stomp", "mqtt");
|
||||
|
||||
when(this.upgradeStrategy.getSupportedVersions()).thenReturn(new String[] { "13" });
|
||||
when(this.upgradeStrategy.getSupportedVersions()).thenReturn(new String[] {"13"});
|
||||
|
||||
this.servletRequest.setMethod("GET");
|
||||
|
||||
@@ -79,6 +79,33 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
|
||||
"STOMP", Collections.<WebSocketExtension>emptyList(), null, handler, attributes);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportedExtensions() throws Exception {
|
||||
|
||||
WebSocketExtension extension1 = new WebSocketExtension("ext1");
|
||||
WebSocketExtension extension2 = new WebSocketExtension("ext2");
|
||||
|
||||
when(this.upgradeStrategy.getSupportedVersions()).thenReturn(new String[] {"13"});
|
||||
when(this.upgradeStrategy.getSupportedExtensions(this.request)).thenReturn(Arrays.asList(extension1));
|
||||
|
||||
this.servletRequest.setMethod("GET");
|
||||
|
||||
WebSocketHttpHeaders headers = new WebSocketHttpHeaders(this.request.getHeaders());
|
||||
headers.setUpgrade("WebSocket");
|
||||
headers.setConnection("Upgrade");
|
||||
headers.setSecWebSocketVersion("13");
|
||||
headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
|
||||
headers.setSecWebSocketExtensions(Arrays.asList(extension1, extension2));
|
||||
|
||||
WebSocketHandler handler = new TextWebSocketHandler();
|
||||
Map<String, Object> attributes = Collections.<String, Object>emptyMap();
|
||||
this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
|
||||
|
||||
verify(this.upgradeStrategy).upgrade(this.request, this.response, null, Arrays.asList(extension1),
|
||||
null, handler, attributes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subProtocolCapableHandler() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user