Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
Jan Bartel 2020-07-06 10:43:01 +02:00
commit 4ab5a6044f
4 changed files with 63 additions and 62 deletions

View File

@ -26,12 +26,10 @@ import org.eclipse.jetty.util.Attributes;
class AsyncAttributes extends Attributes.Wrapper
{
public static final String __ASYNC_PREFIX = "javax.servlet.async.";
private final String _requestURI;
private final String _contextPath;
private final String _pathInContext;
private final ServletPathMapping _mapping;
private ServletPathMapping _mapping;
private final String _queryString;
public AsyncAttributes(Attributes attributes, String requestUri, String contextPath, String pathInContext, ServletPathMapping mapping, String queryString)
@ -69,11 +67,7 @@ class AsyncAttributes extends Attributes.Wrapper
@Override
public Set<String> getAttributeNameSet()
{
Set<String> set = new HashSet<>();
super.getAttributeNameSet().stream()
.filter(name -> !name.startsWith(__ASYNC_PREFIX))
.forEach(set::add);
Set<String> set = new HashSet<>(super.getAttributeNameSet());
set.add(AsyncContext.ASYNC_REQUEST_URI);
set.add(AsyncContext.ASYNC_CONTEXT_PATH);
set.add(AsyncContext.ASYNC_SERVLET_PATH);

View File

@ -244,9 +244,8 @@ public class Dispatcher implements RequestDispatcher
{
private final String _requestURI;
private final String _contextPath;
private final String _servletPath;
private final String _pathInContext;
private final ServletPathMapping _servletPathMapping;
private final String _pathInfo;
private final String _query;
public ForwardAttributes(Attributes attributes, String requestURI, String contextPath, String pathInContext, ServletPathMapping mapping, String query)
@ -254,8 +253,7 @@ public class Dispatcher implements RequestDispatcher
super(attributes);
_requestURI = requestURI;
_contextPath = contextPath;
_pathInfo = mapping == null ? pathInContext : mapping.getPathInfo();
_servletPath = mapping == null ? null : mapping.getServletPath();
_pathInContext = pathInContext;
_servletPathMapping = mapping;
_query = query;
}
@ -268,11 +266,11 @@ public class Dispatcher implements RequestDispatcher
switch (key)
{
case FORWARD_PATH_INFO:
return _pathInfo;
return _servletPathMapping == null ? _pathInContext : _servletPathMapping.getPathInfo();
case FORWARD_REQUEST_URI:
return _requestURI;
case FORWARD_SERVLET_PATH:
return _servletPath;
return _servletPathMapping == null ? null : _servletPathMapping.getServletPath();
case FORWARD_CONTEXT_PATH:
return _contextPath;
case FORWARD_QUERY_STRING:
@ -284,7 +282,7 @@ public class Dispatcher implements RequestDispatcher
}
}
// TODO: should this be __FORWARD_PREFIX?
// If we are forwarded then we hide include attributes
if (key.startsWith(__INCLUDE_PREFIX))
return null;
@ -295,25 +293,21 @@ public class Dispatcher implements RequestDispatcher
public Set<String> getAttributeNameSet()
{
HashSet<String> set = new HashSet<>();
super.getAttributeNameSet().stream()
.filter(name -> !name.startsWith(__INCLUDE_PREFIX))
.filter(name -> !name.startsWith(__FORWARD_PREFIX))
.forEach(set::add);
for (String name : _attributes.getAttributeNameSet())
{
if (!name.startsWith(__INCLUDE_PREFIX) &&
!name.startsWith(__FORWARD_PREFIX))
set.add(name);
}
if (_named == null)
{
if (_pathInfo != null)
set.add(FORWARD_PATH_INFO);
if (_requestURI != null)
set.add(FORWARD_REQUEST_URI);
if (_servletPath != null)
set.add(FORWARD_SERVLET_PATH);
if (_contextPath != null)
set.add(FORWARD_CONTEXT_PATH);
if (_servletPathMapping != null)
set.add(FORWARD_MAPPING);
if (_query != null)
set.add(FORWARD_QUERY_STRING);
set.add(FORWARD_PATH_INFO);
set.add(FORWARD_REQUEST_URI);
set.add(FORWARD_SERVLET_PATH);
set.add(FORWARD_CONTEXT_PATH);
set.add(FORWARD_MAPPING);
set.add(FORWARD_QUERY_STRING);
}
return set;
@ -358,26 +352,21 @@ public class Dispatcher implements RequestDispatcher
*/
class IncludeAttributes extends Attributes.Wrapper
{
private final Request _baseRequest;
private final ContextHandler.Context _sourceContext;
private final ServletPathMapping _sourceMapping;
private final ServletPathMapping _mapping;
private final String _requestURI;
private final String _contextPath;
private final String _servletPath;
private final String _pathInfo;
private final String _pathInContext;
private final String _query;
public IncludeAttributes(Attributes attributes, Request baseRequest, ContextHandler.Context sourceContext, ServletPathMapping sourceMapping, String requestURI, String pathInContext, String query)
{
super(attributes);
ContextHandler.Context context = baseRequest.getContext();
_mapping = baseRequest.getServletPathMapping();
_baseRequest = baseRequest;
_sourceMapping = sourceMapping;
_requestURI = requestURI;
_sourceContext = sourceContext;
_pathInfo = _mapping == null ? pathInContext : _mapping.getPathInfo();
_servletPath = _mapping == null ? null : _mapping.getServletPath();
_contextPath = context == null ? null : context.getContextHandler().getContextPathEncoded();
_pathInContext = pathInContext;
_query = query;
}
@ -399,17 +388,26 @@ public class Dispatcher implements RequestDispatcher
switch (key)
{
case INCLUDE_PATH_INFO:
return _pathInfo;
{
ServletPathMapping mapping = _baseRequest.getServletPathMapping();
return mapping == null ? _pathInContext : mapping.getPathInfo();
}
case INCLUDE_SERVLET_PATH:
return _servletPath;
{
ServletPathMapping mapping = _baseRequest.getServletPathMapping();
return mapping == null ? null : mapping.getServletPath();
}
case INCLUDE_CONTEXT_PATH:
return _contextPath;
{
ContextHandler.Context context = _baseRequest.getContext();
return context == null ? null : context.getContextHandler().getContextPathEncoded();
}
case INCLUDE_QUERY_STRING:
return _query;
case INCLUDE_REQUEST_URI:
return _requestURI;
case INCLUDE_MAPPING:
return _mapping;
return _baseRequest.getServletPathMapping();
default:
break;
}
@ -422,24 +420,20 @@ public class Dispatcher implements RequestDispatcher
public Set<String> getAttributeNameSet()
{
HashSet<String> set = new HashSet<>();
super.getAttributeNameSet().stream()
.filter(name -> !name.startsWith(__INCLUDE_PREFIX))
.forEach(set::add);
for (String name : _attributes.getAttributeNameSet())
{
if (!name.startsWith(__INCLUDE_PREFIX))
set.add(name);
}
if (_named == null)
{
if (_pathInfo != null)
set.add(INCLUDE_PATH_INFO);
if (_requestURI != null)
set.add(INCLUDE_REQUEST_URI);
if (_servletPath != null)
set.add(INCLUDE_SERVLET_PATH);
if (_contextPath != null)
set.add(INCLUDE_CONTEXT_PATH);
if (_mapping != null)
set.add(INCLUDE_MAPPING);
if (_query != null)
set.add(INCLUDE_QUERY_STRING);
set.add(INCLUDE_PATH_INFO);
set.add(INCLUDE_REQUEST_URI);
set.add(INCLUDE_SERVLET_PATH);
set.add(INCLUDE_CONTEXT_PATH);
set.add(INCLUDE_MAPPING);
set.add(INCLUDE_QUERY_STRING);
}
return set;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.servlet;
import java.io.IOException;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Objects;
import java.util.stream.Collectors;
import jakarta.servlet.DispatcherType;
@ -159,7 +160,7 @@ public class FilterMapping implements Dumpable
if (_holder == null)
return false;
if (_dispatches == 0)
return type == REQUEST || type == ASYNC && holder.isAsyncSupported();
return type == REQUEST || type == ASYNC && (_holder != null && _holder.isAsyncSupported());
return (_dispatches & type) != 0;
}
@ -251,7 +252,7 @@ public class FilterMapping implements Dumpable
*/
public void setFilterName(String filterName)
{
_filterName = filterName;
_filterName = Objects.requireNonNull(filterName);
}
/**
@ -259,7 +260,7 @@ public class FilterMapping implements Dumpable
*/
void setFilterHolder(FilterHolder holder)
{
_holder = holder;
_holder = Objects.requireNonNull(holder);
setFilterName(holder.getName());
}

View File

@ -25,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -314,6 +315,7 @@ public class ServletHandlerTest
//add another ordinary mapping
FilterHolder of1 = new FilterHolder(new Source(Source.Origin.DESCRIPTOR, "foo.xml"));
of1.setName("foo");
FilterMapping ofm1 = new FilterMapping();
ofm1.setFilterHolder(of1);
ofm1.setPathSpec("/*");
@ -449,6 +451,16 @@ public class ServletHandlerTest
assertTrue(fm5 == mappings[mappings.length - 1]);
}
@Test
public void testFilterMappingNoFilter() throws Exception
{
FilterMapping mapping = new FilterMapping();
mapping.setPathSpec("/*");
mapping.setFilterName("foo");
//default dispatch is REQUEST, and there is no holder to check for async supported
assertFalse(mapping.appliesTo(DispatcherType.ASYNC));
}
@Test
public void testFilterMappingsMix() throws Exception
{