I think that the following line [2] causes this "null" to be returned. When the specified key is not available in the map, the default is returned, but this default is not added to the map.
With the patch below when I call getAcceptedSubProtocol, the expected value is returned.
diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java
index ff6846f..b44daf7 100644
--- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java
+++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java
@@ -111,7 +111,12 @@ public class ServletUpgradeResponse implements UpgradeResponse
{
String name = entry.getKey();
Collection<String> prepend = entry.getValue();
- List<String> values = headers.getOrDefault(name,headers.containsKey(name)?null:new ArrayList<>());
+ List<String> values = headers.get(name);
+ if (values==null)
+ {
+ values = new ArrayList<>();
+ headers.put(name,values);
+ }
values.addAll(0,prepend);
}
What do you think?
Best Regards,
Violeta Georgieva
[1]
https://www.eclipse.org/jetty/documentation/9.4.x/jetty-websocket-server-api.html