@@ -112,7 +112,7 @@ public Stack executor(Executor executor) {
112112
113113 private RouterOptions options = new RouterOptions ();
114114
115- private $Chi chi = new $Chi (options . isCaseSensitive (), options . isIgnoreTrailingSlash () );
115+ private RadixTree chi = new $Chi ();
116116
117117 private LinkedList <Stack > stack = new LinkedList <>();
118118
@@ -164,8 +164,6 @@ private void defaultParser() {
164164
165165 @ Nonnull @ Override public Router setRouterOptions (@ Nonnull RouterOptions options ) {
166166 this .options = options ;
167- chi .setCaseSensitive (options .isCaseSensitive ());
168- chi .setIgnoreTrailingSlash (options .isIgnoreTrailingSlash ());
169167 return this ;
170168 }
171169
@@ -177,7 +175,7 @@ private void defaultParser() {
177175 if (routes .size () > 0 ) {
178176 throw new IllegalStateException ("Base path must be set before adding any routes." );
179177 }
180- this .basePath = normalizePath (basePath , options . isCaseSensitive () , true );
178+ this .basePath = normalizePath (basePath , false , true );
181179 return this ;
182180 }
183181
@@ -195,8 +193,7 @@ private void defaultParser() {
195193
196194 @ Nonnull @ Override
197195 public Router use (@ Nonnull Predicate <Context > predicate , @ Nonnull Router router ) {
198- RadixTree tree = new $Chi (options .isCaseSensitive (), options .isIgnoreTrailingSlash ())
199- .with (predicate );
196+ RadixTree tree = new $Chi ().with (predicate );
200197 if (trees == null ) {
201198 trees = new ArrayList <>();
202199 }
@@ -208,7 +205,7 @@ public Router use(@Nonnull Predicate<Context> predicate, @Nonnull Router router)
208205 }
209206
210207 @ Nonnull @ Override public Router use (@ Nonnull String path , @ Nonnull Router router ) {
211- String prefix = normalizePath (path , options . isCaseSensitive () , true );
208+ String prefix = normalizePath (path , false , true );
212209 if (prefix .equals ("/" )) {
213210 prefix = "" ;
214211 }
@@ -327,14 +324,10 @@ public Route route(@Nonnull String method, @Nonnull String pattern,
327324
328325 private Route defineRoute (@ Nonnull String method , @ Nonnull String pattern ,
329326 @ Nonnull Route .Handler handler , RadixTree tree ) {
330- /** Make sure router options are in sync: */
331- chi .setCaseSensitive (options .isCaseSensitive ());
332- chi .setIgnoreTrailingSlash (options .isIgnoreTrailingSlash ());
333-
334327 /** Pattern: */
335- StringBuilder pat = new StringBuilder ();
336- stack .stream ().filter (it -> it .pattern != null ).forEach (it -> pat .append (it .pattern ));
337- pat .append (pattern );
328+ StringBuilder patternBuff = new StringBuilder ();
329+ stack .stream ().filter (it -> it .pattern != null ).forEach (it -> patternBuff .append (it .pattern ));
330+ patternBuff .append (pattern );
338331
339332 /** Before: */
340333 Route .Before before = stack .stream ()
@@ -352,24 +345,22 @@ private Route defineRoute(@Nonnull String method, @Nonnull String pattern,
352345 .reduce (null , (it , next ) -> it == null ? next : it .then (next ));
353346
354347 /** Route: */
355- String safePattern = normalizePath (pat .toString (), options .isCaseSensitive (),
356- options .isIgnoreTrailingSlash ());
348+ String safePattern = Router .normalizePath (patternBuff .toString (), false , true );
357349 Route route = new Route (method , safePattern , handler );
358350 route .setPathKeys (Router .pathKeys (safePattern ));
359351 route .setBefore (before );
360352 route .setAfter (after );
361353 route .setDecorator (decorator );
362354 route .setRenderer (renderer );
363355 route .setParsers (parsers );
364- //null, handler, before, decorator, after, renderer,
365- //parsers);
356+
366357 Stack stack = this .stack .peekLast ();
367358 if (stack .executor != null ) {
368359 routeExecutor .put (route , stack .executor );
369360 }
370361 String routePattern = normalizePath (basePath == null
371362 ? safePattern
372- : basePath + safePattern , options . isCaseSensitive (), options . isIgnoreTrailingSlash () );
363+ : basePath + safePattern , false , true );
373364 if (method .equals ("*" )) {
374365 METHODS .forEach (m -> tree .insert (m , routePattern , route ));
375366 } else {
@@ -401,6 +392,10 @@ private Route defineRoute(@Nonnull String method, @Nonnull String pattern,
401392 .compute (source .getLoader (), route , mode , executor , handlers );
402393 route .setPipeline (pipeline );
403394 }
395+ // router options
396+ if (options .isIgnoreCase () || options .isIgnoreTrailingSlash ()) {
397+ chi = chi .options (options .isIgnoreCase (), options .isIgnoreTrailingSlash ());
398+ }
404399 // unwrap executor
405400 worker = ((ForwardingExecutor ) worker ).executor ;
406401 this .stack .forEach (Stack ::clear );
@@ -535,7 +530,7 @@ private Stack push() {
535530 }
536531
537532 private Stack push (String pattern ) {
538- Stack stack = new Stack (normalizePath (pattern , options . isCaseSensitive () , true ));
533+ Stack stack = new Stack (normalizePath (pattern , false , true ));
539534 if (this .stack .size () > 0 ) {
540535 Stack parent = this .stack .getLast ();
541536 stack .executor = parent .executor ;
0 commit comments