Skip to content

Commit

Permalink
Merge pull request #30 from ortus-boxlang/development
Browse files Browse the repository at this point in the history
Beta 22
  • Loading branch information
jclausen authored Nov 15, 2024
2 parents a7d0dee + 71e6335 commit 815071a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Fri Oct 25 15:01:28 UTC 2024
boxlangVersion=1.0.0-beta21
#Fri Nov 01 20:52:59 UTC 2024
boxlangVersion=1.0.0-beta22
jdkVersion=21
version=1.0.0-beta21
version=1.0.0-beta22
group=ortus.boxlang
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class BoxHTTPUndertowExchange implements IBoxHTTPExchange {
/**
* PrintWriter for the response that wraps the channel
*/
PrintWriter writer;
WhitespaceManagingPrintWriter writer;

/**
* The Undertow exchange for this request
Expand Down Expand Up @@ -177,6 +177,8 @@ public void flushResponseBuffer() {
setResponseHeader( "Content-Type", "text/html;charset=UTF-8" );
}

// Update this in case the content type has changed
writer.setWhitespaceCompressionEnabled( context.isWhitespaceCompressionEnabled() );
writer.flush();
getResponseChannel().flush();
} catch ( IOException e ) {
Expand Down Expand Up @@ -527,7 +529,7 @@ public int getResponseStatus() {
public PrintWriter getResponseWriter() {
if ( writer == null ) {
OutputStream outputStream = new BlockingBufferedOutputStream( getResponseChannel() );
writer = new PrintWriter( outputStream, false );
writer = new WhitespaceManagingPrintWriter( new PrintWriter( outputStream, false ), context.isWhitespaceCompressionEnabled() );
}
return writer;
}
Expand Down
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 815071a

Please sign in to comment.