Skip to content

Commit

Permalink
Issue #5025 - wrong welcome file handling with dispatcher.include() a…
Browse files Browse the repository at this point in the history
…nd non-default mapping (#5026)

Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel committed Jul 16, 2020
1 parent ce62664 commit 668174d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,11 @@ protected void sendWelcome(HttpContent content, String pathInContext, boolean en

if (welcome != null)
{
String servletPath = included ? (String)request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH)
: request.getServletPath();

if (_pathInfoOnly)
welcome = URIUtil.addPaths(request.getServletPath(), welcome);
welcome = URIUtil.addPaths(servletPath, welcome);

if (LOG.isDebugEnabled())
LOG.debug("welcome={}", welcome);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.DateGenerator;
Expand Down Expand Up @@ -814,6 +816,48 @@ public void testWelcomeMultipleBasesBase() throws Exception
}
}

@Test
public void testIncludedWelcomeDifferentBase() throws Exception
{
Path altRoot = workDir.getPath().resolve("altroot");
FS.ensureDirExists(altRoot);
Path altIndex = altRoot.resolve("index.html");

ServletHolder defholder = context.addServlet(DefaultServlet.class, "/alt/*");
defholder.setInitParameter("resourceBase", altRoot.toUri().toASCIIString());
defholder.setInitParameter("dirAllowed", "false");
defholder.setInitParameter("redirectWelcome", "false");
defholder.setInitParameter("welcomeServlets", "true");
defholder.setInitParameter("pathInfoOnly", "true");

ServletHolder gwholder = new ServletHolder("gateway", new HttpServlet()
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
req.getRequestDispatcher("/alt/").include(req, resp);
}
});
context.addServlet(gwholder, "/gateway");

String rawResponse;
HttpTester.Response response;

// Test included alt default
rawResponse = connector.getResponse("GET /context/gateway HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
// 9.3 "The Include Method" - when include() is used, FileNotFoundException (and HTTP 500)
// should be used
assertThat(response.toString(), response.getStatus(), is(HttpStatus.INTERNAL_SERVER_ERROR_500));

createFile(altIndex, "<h1>Alt Index</h1>");
rawResponse = connector.getResponse("GET /context/gateway HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.OK_200));
assertThat(response.getContent(), containsString("<h1>Alt Index</h1>"));
}

@Test
public void testWelcomeRedirect() throws Exception
{
Expand Down

0 comments on commit 668174d

Please sign in to comment.