Jetty sequentially tries to process each handler until one of the handlers calls setHandled (true) in the request. I donβt know why ResourceHandler does not do this for "/".
My solution was to reverse the order in which you specify the handlers so that your call is called first. Then check the special url "/" in the url. If you want to pass the request to the ResourceHandler, just go back without declaring the request as processed.
Declare the order of the handlers as follows:
Server server = new Server(8080); CustomHandler default = new CustomHandler(); default.setServer(server); ResourceHandler files = new ResourceHandler(); files.setServer(server); files.setResourceBase("./path/to/resources"); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] {default, files}); server.setHandler(handlers); server.start(); server.join();
And define the CustomHandler descriptor method as follows:
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if(!request.getRequestURI().equals("/")){ return; }
I agree that it would be very elegant if the ResourceHandler simply yields "/" instead of processing the response with 403.
source share