Merge branch 'jetty-9.3.x' into jetty-9.4.x
This commit is contained in:
commit
996253c971
|
@ -413,13 +413,22 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
|
|||
@Override
|
||||
public boolean isUpgradeRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
{
|
||||
if (!"GET".equalsIgnoreCase(request.getMethod()))
|
||||
// Tests sorted by least common to most common.
|
||||
|
||||
String upgrade = request.getHeader("Upgrade");
|
||||
if (upgrade == null)
|
||||
{
|
||||
// not a "GET" request (not a websocket upgrade)
|
||||
// no "Upgrade: websocket" header present.
|
||||
return false;
|
||||
}
|
||||
|
||||
String connection = request.getHeader("connection");
|
||||
if (!"websocket".equalsIgnoreCase(upgrade))
|
||||
{
|
||||
// Not a websocket upgrade
|
||||
return false;
|
||||
}
|
||||
|
||||
String connection = request.getHeader("Connection");
|
||||
if (connection == null)
|
||||
{
|
||||
// no "Connection: upgrade" header present.
|
||||
|
@ -444,16 +453,9 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
|
|||
return false;
|
||||
}
|
||||
|
||||
String upgrade = request.getHeader("Upgrade");
|
||||
if (upgrade == null)
|
||||
if (!"GET".equalsIgnoreCase(request.getMethod()))
|
||||
{
|
||||
// no "Upgrade: websocket" header present.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!"websocket".equalsIgnoreCase(upgrade))
|
||||
{
|
||||
LOG.debug("Not a 'Upgrade: WebSocket' (was [Upgrade: " + upgrade + "])");
|
||||
// not a "GET" request (not a websocket upgrade)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -184,16 +184,18 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
return;
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug(".doFilter({}) - {}",fname,chain);
|
||||
}
|
||||
|
||||
if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse))
|
||||
try
|
||||
{
|
||||
HttpServletRequest httpreq = (HttpServletRequest) request;
|
||||
HttpServletResponse httpresp = (HttpServletResponse) response;
|
||||
|
||||
if (!factory.isUpgradeRequest(httpreq, httpresp))
|
||||
{
|
||||
// Not an upgrade request, skip it
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
// Since this is a filter, we need to be smart about determining the target path
|
||||
String contextPath = httpreq.getContextPath();
|
||||
String target = httpreq.getRequestURI();
|
||||
|
@ -202,10 +204,6 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
target = target.substring(contextPath.length());
|
||||
}
|
||||
|
||||
if (factory.isUpgradeRequest(httpreq,httpresp))
|
||||
{
|
||||
LOG.debug("target = [{}]",target);
|
||||
|
||||
MappedResource<WebSocketCreator> resource = pathmap.getMatch(target);
|
||||
if (resource == null)
|
||||
{
|
||||
|
@ -218,7 +216,11 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
if(LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("WebSocket Upgrade detected on {} for endpoint {}", target, resource);
|
||||
}
|
||||
|
||||
WebSocketCreator creator = resource.getResource();
|
||||
|
||||
|
@ -241,6 +243,13 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
return;
|
||||
}
|
||||
}
|
||||
catch (ClassCastException e)
|
||||
{
|
||||
// We are in some kind of funky non-http environment.
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("Not a HttpServletRequest, skipping WebSocketUpgradeFilter");
|
||||
}
|
||||
}
|
||||
|
||||
// not an Upgrade request
|
||||
|
|
Loading…
Reference in New Issue