@@ -61,7 +61,7 @@ public class MyResourceHandler extends ResourceHandler
6161 public MyResourceHandler (final String strip , final String home )
6262 {
6363 super ();
64- this .strip = StringUtil .getNonEmpty (strip );
64+ this .strip = strip == null ? null : StringUtil .token ( StringUtil . getNonEmpty (strip . toLowerCase ()), 0 , "/" );
6565 this .home = home ;
6666 whiteList = new HashSet <>();
6767 }
@@ -70,19 +70,23 @@ public MyResourceHandler(final String strip, final String home)
7070
7171 String update (String url )
7272 {
73-
74- if (strip != null && url .startsWith (strip ) && (url .length () == strip .length () || url .charAt (strip .length ()) == '/' ))
73+ final String urlLow = url .toLowerCase ();
74+ int pos = StringUtil .posOfToken (urlLow , strip , "/" , 0 );
75+ if (pos >= 0 )
7576 {
76- url = StringUtil .removeToken (url , 0 , "/" );
77+ pos = urlLow .indexOf (strip );
78+ url = url .substring (0 , pos ) + url .substring (pos + StringUtil .length (strip ) + 1 );
7779 }
80+
7881 if ("" .equals (url ) || "/" .equals (url ))
7982 {
8083 return home ;
8184 }
8285 else if (!whiteList .isEmpty ())
8386 {
8487 final String base = StringUtil .token (url , 0 , "/" );
85- if (!whiteList .contains (base .toLowerCase ()))
88+ final String base2 = StringUtil .token (url , 2 , "/" ); // http://host:port/root
89+ if (!whiteList .contains (base .toLowerCase ()) && (base2 == null || !whiteList .contains (base2 .toLowerCase ())))
8690 {
8791 return null ;
8892 }
@@ -110,6 +114,9 @@ public String toString()
110114 @ Override
111115 public boolean handle (final Request request , final Response response , final Callback callback ) throws Exception
112116 {
117+ final String context = request .getContext ().getContextPath ();
118+ if (StringUtil .isEmpty (context ))
119+ return false ;
113120 final HttpURI uri = request .getHttpURI ();
114121 final String uriString = update (uri .asString ());
115122 if (uriString == null )
0 commit comments