Issue #911 encode requestURI in startAsync(req,res)
This commit is contained in:
parent
ab579d542b
commit
68340a94d0
|
@ -95,7 +95,7 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The path in the context
|
* @return The path in the context (encoded with possible query string)
|
||||||
*/
|
*/
|
||||||
public String getPath()
|
public String getPath()
|
||||||
{
|
{
|
||||||
|
@ -137,9 +137,12 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable
|
||||||
_dispatchContext=context;
|
_dispatchContext=context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path encoded URI
|
||||||
|
*/
|
||||||
public void setDispatchPath(String path)
|
public void setDispatchPath(String path)
|
||||||
{
|
{
|
||||||
_dispatchPath=URIUtil.decodePath(path);
|
_dispatchPath=path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void completed()
|
public void completed()
|
||||||
|
|
|
@ -1248,6 +1248,8 @@ public class Request implements HttpServletRequest
|
||||||
@Override
|
@Override
|
||||||
public RequestDispatcher getRequestDispatcher(String path)
|
public RequestDispatcher getRequestDispatcher(String path)
|
||||||
{
|
{
|
||||||
|
// path is encoded, potentially with query
|
||||||
|
|
||||||
if (path == null || _context == null)
|
if (path == null || _context == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -1260,7 +1262,7 @@ public class Request implements HttpServletRequest
|
||||||
relTo = relTo.substring(0,slash + 1);
|
relTo = relTo.substring(0,slash + 1);
|
||||||
else
|
else
|
||||||
relTo = "/";
|
relTo = "/";
|
||||||
path = URIUtil.addPaths(relTo,path);
|
path = URIUtil.addPaths(URIUtil.encodePath(relTo),path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _context.getRequestDispatcher(path);
|
return _context.getRequestDispatcher(path);
|
||||||
|
@ -2239,7 +2241,7 @@ public class Request implements HttpServletRequest
|
||||||
_async=new AsyncContextState(state);
|
_async=new AsyncContextState(state);
|
||||||
AsyncContextEvent event = new AsyncContextEvent(_context,_async,state,this,servletRequest,servletResponse);
|
AsyncContextEvent event = new AsyncContextEvent(_context,_async,state,this,servletRequest,servletResponse);
|
||||||
event.setDispatchContext(getServletContext());
|
event.setDispatchContext(getServletContext());
|
||||||
event.setDispatchPath(URIUtil.addPaths(getServletPath(),getPathInfo()));
|
event.setDispatchPath(URIUtil.encodePath(URIUtil.addPaths(getServletPath(),getPathInfo())));
|
||||||
state.startAsync(event);
|
state.startAsync(event);
|
||||||
return _async;
|
return _async;
|
||||||
}
|
}
|
||||||
|
|
|
@ -552,7 +552,7 @@ public class Server extends HandlerWrapper implements Attributes
|
||||||
// this is a dispatch with a path
|
// this is a dispatch with a path
|
||||||
ServletContext context=event.getServletContext();
|
ServletContext context=event.getServletContext();
|
||||||
String query=baseRequest.getQueryString();
|
String query=baseRequest.getQueryString();
|
||||||
baseRequest.setURIPathQuery(URIUtil.encodePath(URIUtil.addPaths(context==null?null:context.getContextPath(), path)));
|
baseRequest.setURIPathQuery(URIUtil.addPaths(context==null?null:URIUtil.encodePath(context.getContextPath()), path));
|
||||||
HttpURI uri = baseRequest.getHttpURI();
|
HttpURI uri = baseRequest.getHttpURI();
|
||||||
baseRequest.setPathInfo(uri.getDecodedPath());
|
baseRequest.setPathInfo(uri.getDecodedPath());
|
||||||
if (uri.getQuery()!=null)
|
if (uri.getQuery()!=null)
|
||||||
|
|
|
@ -2041,6 +2041,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
||||||
@Override
|
@Override
|
||||||
public RequestDispatcher getRequestDispatcher(String uriInContext)
|
public RequestDispatcher getRequestDispatcher(String uriInContext)
|
||||||
{
|
{
|
||||||
|
// uriInContext is encoded, potentially with query
|
||||||
|
|
||||||
if (uriInContext == null)
|
if (uriInContext == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.util.TypeUtil;
|
import org.eclipse.jetty.util.TypeUtil;
|
||||||
|
import org.eclipse.jetty.util.URIUtil;
|
||||||
import org.eclipse.jetty.util.UrlEncoded;
|
import org.eclipse.jetty.util.UrlEncoded;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
@ -147,13 +148,22 @@ public class EncodedURITest
|
||||||
{
|
{
|
||||||
String response = _connector.getResponse("GET /context%20path/async%20servlet/path%20info HTTP/1.0\n\n");
|
String response = _connector.getResponse("GET /context%20path/async%20servlet/path%20info HTTP/1.0\n\n");
|
||||||
assertThat(response,startsWith("HTTP/1.1 200 "));
|
assertThat(response,startsWith("HTTP/1.1 200 "));
|
||||||
assertThat(response,Matchers.containsString("requestURI=/context%20path/test%20servlet/path%20info"));
|
assertThat(response,Matchers.containsString("requestURI=/context%20path/test servlet/path info"));
|
||||||
assertThat(response,Matchers.containsString("contextPath=/context path"));
|
assertThat(response,Matchers.containsString("contextPath=/context path"));
|
||||||
assertThat(response,Matchers.containsString("servletPath=/test servlet"));
|
assertThat(response,Matchers.containsString("servletPath=/test servlet"));
|
||||||
assertThat(response,Matchers.containsString("pathInfo=/path info"));
|
assertThat(response,Matchers.containsString("pathInfo=/path info"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAsyncServletTestServletEncoded() throws Exception
|
||||||
|
{
|
||||||
|
String response = _connector.getResponse("GET /context%20path/async%20servlet/path%20info?encode=true HTTP/1.0\n\n");
|
||||||
|
assertThat(response,startsWith("HTTP/1.1 200 "));
|
||||||
|
assertThat(response,Matchers.containsString("requestURI=/context%20path/test%20servlet/path%20info"));
|
||||||
|
assertThat(response,Matchers.containsString("contextPath=/context path"));
|
||||||
|
assertThat(response,Matchers.containsString("servletPath=/test servlet"));
|
||||||
|
assertThat(response,Matchers.containsString("pathInfo=/path info"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class TestServlet extends HttpServlet
|
public static class TestServlet extends HttpServlet
|
||||||
|
@ -180,7 +190,7 @@ public class EncodedURITest
|
||||||
:request.startAsync();
|
:request.startAsync();
|
||||||
|
|
||||||
if (Boolean.parseBoolean(request.getParameter("encode")))
|
if (Boolean.parseBoolean(request.getParameter("encode")))
|
||||||
async.dispatch("/test%20servlet"+URLEncoder.encode(request.getPathInfo(),"UTF-8"));
|
async.dispatch("/test%20servlet"+URIUtil.encodePath(request.getPathInfo()));
|
||||||
else
|
else
|
||||||
async.dispatch("/test servlet/path info"+request.getPathInfo());
|
async.dispatch("/test servlet/path info"+request.getPathInfo());
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue