Skip to content

Commit

Permalink
COMMANDBOX-1625
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Jul 1, 2024
1 parent addb745 commit 06bab10
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/runwar/undertow/WelcomeFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.undertow.util.CanonicalPathUtils;
import io.undertow.util.RedirectBuilder;
import io.undertow.util.StatusCodes;
import io.undertow.util.Headers;

public class WelcomeFileHandler implements HttpHandler {

Expand All @@ -26,7 +27,14 @@ public class WelcomeFileHandler implements HttpHandler {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
Resource resource = resourceManager.getResource(canonicalize(exchange.getRelativePath()));
if (resource != null && resource.isDirectory() && exchange.getRelativePath().endsWith("/")) {
if (resource != null && resource.isDirectory()) {
if (!exchange.getRequestPath().endsWith("/")) {
exchange.setStatusCode(StatusCodes.FOUND);
exchange.getResponseHeaders().put(Headers.LOCATION,
RedirectBuilder.redirect(exchange, exchange.getRelativePath() + "/", true));
exchange.endExchange();
return;
}
Resource indexResource = getIndexFiles(exchange, resourceManager, resource.getPath(), welcomeFiles);
if (indexResource != null) {
String newPath = indexResource.getPath();
Expand Down

0 comments on commit 06bab10

Please sign in to comment.