Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-10-21 01:32:54 +0000
committerGreg Wilkins2013-10-21 01:32:54 +0000
commit82a991dd07cd79d32a24ed2d657098cad4ba79d8 (patch)
tree548ac4aae2589c8b9d9b3c1d91c6d5da907d9d64 /jetty-http
parent9ec06de3a3c8c0db056dd1fc0778b53c9ef81358 (diff)
parent24c1b30495551a1d4ab86052af60b54159c04f06 (diff)
downloadorg.eclipse.jetty.project-82a991dd07cd79d32a24ed2d657098cad4ba79d8.tar.gz
org.eclipse.jetty.project-82a991dd07cd79d32a24ed2d657098cad4ba79d8.tar.xz
org.eclipse.jetty.project-82a991dd07cd79d32a24ed2d657098cad4ba79d8.zip
Merge remote-tracking branch 'origin/master' into jetty-9.1
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 73be07efd8..6c9452baa1 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
@@ -67,6 +67,7 @@ public class PathMapTest
{ "/animal/path.gz", "5"},
{ "/Other/path", "8"},
{ "/\u20ACuro/path", "11"},
+ { "/", "10"},
};
for (String[] test : tests)
@@ -80,8 +81,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