jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

Review DefaultServlet behaviours for including and pathInfoOnly

Open janbartel opened this issue 2 years ago • 2 comments
trafficstars

Jetty version(s) jetty-12

Jetty Environment ee10, but probably ee9//8 as well

Questions to resolve via a review of DefaultServlet behaviour:

  1. if a welcome servlet is being served via an include, why do we use the servletPath from the request, rather than just the pathInfo (as is the case when not being included): see https://github.com/eclipse/jetty.project/blob/jetty-12.0.x/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java#L638 Given:
      _contextHandler = new ServletContextHandler();
      _contextHandler.setContextPath("/context");
      _contextHandler.setBaseResourceAsPath("/some/path/contextResources");
      _contextHandler.setWelcomeFiles(new String[] {"index.x"});
      ServletHolder rHolder = _contextHandler.addServlet(DefaultServlet.class, "/r/*");
      rHolder.setInitParameter("welcomeServlets", "true");
      _contextHandler.addServlet(RogerThatServlet.class, "*.x");

The request /context/r/ is dispatched to /index.x, which is handled by the RogerThatServlet as expected. However, a request such as /context/dispatch?include=/r/ - where we do an include dispatch to the DefaultServlet with /r/ - results in trying to find a servlet that matches /r/index.x. That will be the same servlet (see line 641) and we don't handle the welcome.

  1. why do we use the getEncodedPathInContext() method in DefaultServlet.doGet() to calculate which resource to service, but yet that value is then ignored when we need to serve a welcome servlet, and we use the getPathInfo() from the request instead?

janbartel avatar Sep 28 '23 02:09 janbartel

@gregw does your latest PR for the ResourceServlet address this?

janbartel avatar Jul 10 '24 06:07 janbartel

I don't think this is an issue.

The servlet mapping for "/r/*" has precedence over "*.x", so the welcome servlet matches itself.

@lorban @janbartel thoughts?

gregw avatar Aug 28 '24 23:08 gregw

@janbartel I'm going to close this unless you have any thoughts to the contrary?

gregw avatar Apr 14 '25 06:04 gregw