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()
|
||||
{
|
||||
|
@ -137,9 +137,12 @@ public class AsyncContextEvent extends AsyncEvent implements Runnable
|
|||
_dispatchContext=context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path encoded URI
|
||||
*/
|
||||
public void setDispatchPath(String path)
|
||||
{
|
||||
_dispatchPath=URIUtil.decodePath(path);
|
||||
_dispatchPath=path;
|
||||
}
|
||||
|
||||
public void completed()
|
||||
|
|
|
@ -1248,6 +1248,8 @@ public class Request implements HttpServletRequest
|
|||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String path)
|
||||
{
|
||||
// path is encoded, potentially with query
|
||||
|
||||
if (path == null || _context == null)
|
||||
return null;
|
||||
|
||||
|
@ -1260,7 +1262,7 @@ public class Request implements HttpServletRequest
|
|||
relTo = relTo.substring(0,slash + 1);
|
||||
else
|
||||
relTo = "/";
|
||||
path = URIUtil.addPaths(relTo,path);
|
||||
path = URIUtil.addPaths(URIUtil.encodePath(relTo),path);
|
||||
}
|
||||
|
||||
return _context.getRequestDispatcher(path);
|
||||
|
@ -2239,7 +2241,7 @@ public class Request implements HttpServletRequest
|
|||
_async=new AsyncContextState(state);
|
||||
AsyncContextEvent event = new AsyncContextEvent(_context,_async,state,this,servletRequest,servletResponse);
|
||||
event.setDispatchContext(getServletContext());
|
||||
event.setDispatchPath(URIUtil.addPaths(getServletPath(),getPathInfo()));
|
||||
event.setDispatchPath(URIUtil.encodePath(URIUtil.addPaths(getServletPath(),getPathInfo())));
|
||||
state.startAsync(event);
|
||||
return _async;
|
||||
}
|
||||
|
|
|
@ -552,7 +552,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
// this is a dispatch with a path
|
||||
ServletContext context=event.getServletContext();
|
||||
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();
|
||||
baseRequest.setPathInfo(uri.getDecodedPath());
|
||||
if (uri.getQuery()!=null)
|
||||
|
|
|
@ -2041,6 +2041,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
|
|||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String uriInContext)
|
||||
{
|
||||
// uriInContext is encoded, potentially with query
|
||||
|
||||
if (uriInContext == 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.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.UrlEncoded;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
|
@ -147,14 +148,23 @@ public class EncodedURITest
|
|||
{
|
||||
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,Matchers.containsString("requestURI=/context%20path/test servlet/path info"));
|
||||
assertThat(response,Matchers.containsString("contextPath=/context path"));
|
||||
assertThat(response,Matchers.containsString("servletPath=/test servlet"));
|
||||
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
|
||||
{
|
||||
|
@ -180,7 +190,7 @@ public class EncodedURITest
|
|||
:request.startAsync();
|
||||
|
||||
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
|
||||
async.dispatch("/test servlet/path info"+request.getPathInfo());
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue