Skip to content

Commit

Permalink
Use regex for WO URL rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Jul 13, 2023
1 parent 6f26bc0 commit 02c15fb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ng-appserver/src/main/java/ng/appserver/NGApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -461,19 +463,29 @@ public NGActionResults defaultResponse( final NGRequest request ) {
*/
private void cleanupWOURL( final NGRequest request ) {

String woStart = "/Apps/WebObjects/%s.woa/1".formatted( properties().propWOApplicationName() );
final Pattern pattern = Pattern.compile( "^/(cgi-bin|Apps)/WebObjects/" + properties().propWOApplicationName() + ".woa(/[0-9])?" );
final Matcher matcher = pattern.matcher( request.uri() );

if( matcher.find() ) {
request.setURI( request.uri().substring( matcher.group().length() ) );
logger.info( "Rewrote WO URI to {}", request.uri() );
}

/*
String woStart = "/Apps/WebObjects/%s.woa/1".formatted( properties().propWOApplicationName() );
if( request.uri().startsWith( woStart ) ) {
request.setURI( request.uri().substring( woStart.length() ) );
logger.info( "Rewrote WO URI to {}", request.uri() );
}

woStart = "/cgi-bin/WebObjects/%s.woa".formatted( properties().propWOApplicationName() );

if( request.uri().startsWith( woStart ) ) {
request.setURI( request.uri().substring( woStart.length() ) );
logger.info( "Rewrote WO URI to {}", request.uri() );
}
*/
}

/**
Expand Down

0 comments on commit 02c15fb

Please sign in to comment.