Project: mule
Issue MULE-6986: http:static-resource-handler fails when request path is '/'
Given a http:inbound-endpoint with no context path, and a http:static-resource-handler with a resourceBase set, expect that visiting http://server:port should redirect or service http://server:port/index.html. Noted the following issues: 1) Server actually sends a 302 redirect to '//', which is not handled well by modern browsers (Chrome) 2) Visiting http://server:port// actually returns the contents of index.html 3) As a side-issue, visiting http://server:port/index.html if resourceBase does not have a trailing slash results in a file not found error (does not add the necessary slash) Looking at the source here: https://github.com/mulesoft/mule/blob/8de5e6b1de40e8d5f792e8e0f0b9d1de7506c2d8/transports/http/src/main/java/org/mule/transport/http/components/StaticResourceMessageProcessor.java The issue is that the request path is stripped back from '/' to '' here: {code} String path = event.getMessage().getInboundProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY); String contextPath = event.getMessage().getInboundProperty(HttpConnector.HTTP_CONTEXT_PATH_PROPERTY); // Remove the contextPath from the endpoint from the request as this isn't part of the path. path = path.substring(contextPath.length()); {code} And so the following code fails to match on 'path.endsWith': {code} if (file.isDirectory() && path.endsWith("/")) { file = new File(resourceBase + path + defaultFile); } {code} And the subsequent code block to redirect is used. The functional test cases don't catch this because the context path is not the same as the request path.
Story points: 5