Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-10-21 01:19:16 +0000
committerGreg Wilkins2013-10-21 01:20:34 +0000
commit24c1b30495551a1d4ab86052af60b54159c04f06 (patch)
tree4c136cb0a487e9c4d24d6fd7de120fae79e47802 /jetty-http
parentad64ca831a212b3c8cd9a10684512d85c5669c29 (diff)
downloadorg.eclipse.jetty.project-24c1b30495551a1d4ab86052af60b54159c04f06.tar.gz
org.eclipse.jetty.project-24c1b30495551a1d4ab86052af60b54159c04f06.tar.xz
org.eclipse.jetty.project-24c1b30495551a1d4ab86052af60b54159c04f06.zip
418732 - Add whiteListByPath mode to IPAccessHandler
Fixed the contribution. The PathMap changes were not correct as "" is the pattern for "/" path only. Also removed the use of the lazy list
Diffstat (limited to 'jetty-http')
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/PathMap.java47
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/PathMapTest.java5
2 files changed, 24 insertions, 28 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/PathMap.java b/jetty-http/src/main/java/org/eclipse/jetty/http/PathMap.java
index 02175fd102..00b77a5a16 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/PathMap.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/PathMap.java
@@ -18,6 +18,7 @@
package org.eclipse.jetty.http;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -39,6 +40,7 @@ import org.eclipse.jetty.util.URIUtil;
* /foo/* - a prefix path specification (must end '/*').
* *.ext - a suffix path specification.
* / - the default path specification.
+ * "" - the / path specification
* </PRE>
* Matching is performed in the following order <NL>
* <LI>Exact match.
@@ -134,7 +136,6 @@ public class PathMap<O> extends HashMap<String,O>
MappedEntry<O> entry = new MappedEntry<>("",object);
entry.setMapped("");
_exactMap.put("", entry);
- _prefixDefault = entry;
return super.put("", object);
}
@@ -268,20 +269,22 @@ public class PathMap<O> extends HashMap<String,O>
/** Get all entries matched by the path.
* Best match first.
* @param path Path to match
- * @return LazyList of Map.Entry instances key=pathSpec
+ * @return List of Map.Entry instances key=pathSpec
*/
- public Object getLazyMatches(String path)
+ public List<? extends Map.Entry<String,O>> getMatches(String path)
{
MappedEntry<O> entry;
- Object entries=null;
+ List<MappedEntry<O>> entries=new ArrayList<>();
if (path==null)
- return LazyList.getList(entries);
+ return entries;
+ if (path.length()==0)
+ return _defaultSingletonList;
// try exact match
entry=_exactMap.get(path);
if (entry!=null)
- entries=LazyList.add(entries,entry);
+ entries.add(entry);
// prefix search
int l=path.length();
@@ -294,14 +297,14 @@ public class PathMap<O> extends HashMap<String,O>
break;
String key = entry.getKey();
if (key.length()-2>=path.length() || path.charAt(key.length()-2)=='/')
- entries=LazyList.add(entries,entry);
+ entries.add(entry);
i=key.length()-3;
}
// Prefix Default
if (_prefixDefault!=null)
- entries=LazyList.add(entries,_prefixDefault);
+ entries.add(_prefixDefault);
// Extension search
i=0;
@@ -310,32 +313,24 @@ public class PathMap<O> extends HashMap<String,O>
{
entry=suffix_map.get(path,i+1,l-i-1);
if (entry!=null)
- entries=LazyList.add(entries,entry);
+ entries.add(entry);
}
- // Default
- if (_default!=null)
+ // root match
+ if ("/".equals(path))
{
- // Optimization for just the default
- if (entries==null)
- return _defaultSingletonList;
-
- entries=LazyList.add(entries,_default);
+ entry=_exactMap.get("");
+ if (entry!=null)
+ entries.add(entry);
}
+
+ // Default
+ if (_default!=null)
+ entries.add(_default);
return entries;
}
- /* --------------------------------------------------------------- */
- /** Get all entries matched by the path.
- * Best match first.
- * @param path Path to match
- * @return List of Map.Entry instances key=pathSpec
- */
- public List<Map.Entry<String,O>> getMatches(String path)
- {
- return LazyList.getList(getLazyMatches(path));
- }
/* --------------------------------------------------------------- */
/** Return whether the path matches any entries in the PathMap,
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/PathMapTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/PathMapTest.java
index 65481f1435..f400ad26e9 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/PathMapTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/PathMapTest.java
@@ -65,6 +65,7 @@ public class PathMapTest
{ "/animal/path.gz", "5"},
{ "/Other/path", "8"},
{ "/\u20ACuro/path", "11"},
+ { "/", "10"},
};
for (String[] test : tests)
@@ -78,8 +79,8 @@ public class PathMapTest
p.getMatches("/animal/bird/path.tar.gz").toString());
assertEquals("Dir matches", "[/animal/fish/*=4, /animal/*=5, /=8]", p.getMatches("/animal/fish/").toString());
assertEquals("Dir matches", "[/animal/fish/*=4, /animal/*=5, /=8]", p.getMatches("/animal/fish").toString());
- assertEquals("Dir matches", "[/=8]", p.getMatches("/").toString());
- assertEquals("Dir matches", "[=10, /=8]", p.getMatches("").toString());
+ assertEquals("Root matches", "[=10, /=8]",p.getMatches("/").toString());
+ assertEquals("Dir matches", "[/=8]", p.getMatches("").toString());
assertEquals("pathMatch exact", "/Foo/bar", PathMap.pathMatch("/Foo/bar", "/Foo/bar"));
assertEquals("pathMatch prefix", "/Foo", PathMap.pathMatch("/Foo/*", "/Foo/bar"));

Back to the top