Skip to content

Commit

Permalink
Merge pull request #6030 from eclipse/jetty-10.0.x-6028-root-getconte…
Browse files Browse the repository at this point in the history
…xtpath

Issue #6028 - Request.getContextPath() for root context should be empty string (Jetty 10)
  • Loading branch information
joakime committed Mar 10, 2021
2 parents 06ea681 + 2710f22 commit 1df8652
Showing 1 changed file with 33 additions and 0 deletions.
Expand Up @@ -59,6 +59,7 @@
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;

import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.logging.StacklessLogging;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.RoleInfo;
Expand All @@ -84,6 +85,8 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -691,6 +694,36 @@ public void contextInitialized(ServletContextEvent sce)
_server.start();
}

@ParameterizedTest
@ValueSource(strings = {"/", ""})
public void testGetContextPathRoot(String inputContextPath) throws Exception
{
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath(inputContextPath);
contextHandler.addServlet(new ServletHolder(new HttpServlet()
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
resp.setContentType("text/plain");
resp.setCharacterEncoding("utf-8");
resp.getWriter().printf("getContextPath()=[%s]", req.getContextPath());
}
}), "/dump");
_server.setHandler(contextHandler);
_server.start();

StringBuilder rawRequest = new StringBuilder();
rawRequest.append("GET /dump HTTP/1.1\r\n");
rawRequest.append("Host: local\r\n");
rawRequest.append("Connection: close\r\n");
rawRequest.append("\r\n");
String rawResponse = _connector.getResponse(rawRequest.toString());
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertEquals(200, response.getStatus(), "response status");
assertEquals("getContextPath()=[]", response.getContent(), "response content");
}

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

0 comments on commit 1df8652

Please sign in to comment.