diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java index deef5aba708f..f6c0d3e50b2d 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/ClientUpgradeRequest.java @@ -298,10 +298,13 @@ public void upgrade(HttpResponse response, HttpConnectionOverHTTP httpConnection } } - // Put requested internal Extensions into the negotiatedExtension list. + // Insert client requested internal Extensions into the negotiatedExtension list from the server. + // The order of extensions in the response is assumed to be the same as what the client negotiated. int i = 0; for (ExtensionConfig reqConfig : requestedExtensions) { + // If this is an internal extension insert in negotiatedExtensions at position i. + // If this is not an internal extension we must advance i only if this extension was negotiated by the server. if (reqConfig.isInternalExtension()) negotiatedExtensions.add(i++, reqConfig); else if (i < negotiatedExtensions.size() && reqConfig.getName().equals(negotiatedExtensions.get(i).getName())) diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java index d89854a29f00..0d3e65310ff6 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/WebSocketNegotiationTest.java @@ -369,7 +369,8 @@ public static Stream internalExtensionScenarios() throws Exception Arguments.of("ext1, ext2, @int1", "ext1, ext2, @int1"), Arguments.of("@int1, ext1, @int2, ext2, @int3", "@int1, ext1, @int2, ext2, @int3"), Arguments.of("ext1, ext1, ext1, @int1, ext2", "ext1, @int1, ext2"), - Arguments.of("ext1, @int1, ext1, ext1, ext2", "ext1, @int1, ext2") + Arguments.of("ext1, @int1, ext1, ext1, ext2", "ext1, @int1, ext2"), + Arguments.of("ext1, ext2, ext3, @int1", "ext1, ext2, ext3, @int1") ); }