Skip to content

Commit

Permalink
BL-730
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Nov 6, 2024
1 parent 4c08a23 commit bb44cf5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/ortus/boxlang/web/handlers/WelcomeFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.undertow.server.handlers.resource.Resource;
import io.undertow.server.handlers.resource.ResourceManager;
import io.undertow.util.CanonicalPathUtils;
import io.undertow.util.RedirectBuilder;
import io.undertow.util.StatusCodes;

/**
* The WelcomeFileHandler is an Undertow HttpHandler that serves welcome files.
Expand Down Expand Up @@ -59,6 +61,15 @@ public WelcomeFileHandler( final HttpHandler next, ResourceManager resourceManag
public void handleRequest( final HttpServerExchange exchange ) throws Exception {
Resource resource = resourceManager.getResource( canonicalize( exchange.getRelativePath() ) );
if ( resource != null && resource.isDirectory() ) {
// First ensure that the directory has a trailing slash, and if not, redirect it
if ( !exchange.getRequestPath().endsWith( "/" ) ) {
exchange.setStatusCode( StatusCodes.FOUND );
exchange.getResponseHeaders().put( io.undertow.util.Headers.LOCATION,
RedirectBuilder.redirect( exchange, exchange.getRelativePath() + "/", true ) );
exchange.endExchange();
return;
}
// if it's a directory and we have the trailing slash, then let's look for welcome files
Resource indexResource = getIndexFiles( exchange, resourceManager, resource.getPath(), welcomeFiles );
if ( indexResource != null ) {
String newPath = indexResource.getPath();
Expand Down

0 comments on commit bb44cf5

Please sign in to comment.