Merge pull request #6655 from eclipse/jetty-10.0.x-6654-websocket-upgrade-npe-request-cookies

Issue #6654 - Fix NPEs from bad Servlet API use
This commit is contained in:
Joakim Erdfelt 2021-08-25 13:48:30 -05:00 committed by GitHub
commit 3badb8629f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 6 deletions

View File

@ -29,6 +29,7 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@ -90,9 +91,17 @@ public class ServerUpgradeRequest
{ {
if (cookies == null) if (cookies == null)
{ {
cookies = Arrays.stream(request.getCookies()) Cookie[] reqCookies = request.getCookies();
.map(c -> new HttpCookie(c.getName(), c.getValue())) if (reqCookies != null)
.collect(Collectors.toList()); {
cookies = Arrays.stream(reqCookies)
.map(c -> new HttpCookie(c.getName(), c.getValue()))
.collect(Collectors.toList());
}
else
{
cookies = Collections.emptyList();
}
} }
return cookies; return cookies;
@ -135,10 +144,13 @@ public class ServerUpgradeRequest
{ {
Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Enumeration<String> headerNames = request.getHeaderNames(); Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) if (headerNames != null)
{ {
String name = headerNames.nextElement(); while (headerNames.hasMoreElements())
headers.put(name, Collections.list(request.getHeaders(name))); {
String name = headerNames.nextElement();
headers.put(name, Collections.list(request.getHeaders(name)));
}
} }
return headers; return headers;
} }