Skip to content

Commit

Permalink
Issue #4985 - revert changes from 9.4 merge to Include, Forward and A…
Browse files Browse the repository at this point in the history
…sync Attributes

The proper ServletPathMapping is not set on the baseRequest when these are constructed
so we can't save fields from this in the constructor. The ServletPathMapping is
later set in the ServletHandler.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jul 6, 2020
1 parent 33852f5 commit 085a611
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@

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)
Expand Down Expand Up @@ -69,11 +67,7 @@ public Object getAttribute(String key)
@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);
Expand Down
96 changes: 45 additions & 51 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,16 @@ private class ForwardAttributes extends Attributes.Wrapper
{
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)
{
super(attributes);
_requestURI = requestURI;
_contextPath = contextPath;
_pathInfo = mapping == null ? pathInContext : mapping.getPathInfo();
_servletPath = mapping == null ? null : mapping.getServletPath();
_pathInContext = pathInContext;
_servletPathMapping = mapping;
_query = query;
}
Expand All @@ -268,11 +266,11 @@ public Object getAttribute(String key)
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:
Expand All @@ -284,7 +282,7 @@ public Object getAttribute(String key)
}
}

// TODO: should this be __FORWARD_PREFIX?
// If we are forwarded then we hide include attributes
if (key.startsWith(__INCLUDE_PREFIX))
return null;

Expand All @@ -295,25 +293,21 @@ public Object getAttribute(String key)
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;
Expand Down Expand Up @@ -358,26 +352,21 @@ public void removeAttribute(String name)
*/
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;
}

Expand All @@ -399,17 +388,26 @@ public Object getAttribute(String key)
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;
}
Expand All @@ -422,24 +420,20 @@ public Object getAttribute(String key)
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;
Expand Down

0 comments on commit 085a611

Please sign in to comment.