Skip to content

Commit

Permalink
Issue jetty#5025 - wrong welcome file handling with dispatcher.includ…
Browse files Browse the repository at this point in the history
…e() and non-default mapping

Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
  • Loading branch information
grgrzybek committed Jul 4, 2020
1 parent 7d8e56b commit c7d114f
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 @@ -401,8 +401,13 @@ 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 (servletPath == null)
servletPath = 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 @@ -41,6 +41,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 @@ -813,6 +815,46 @@ 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 c7d114f

Please sign in to comment.