private Handler findHandler(HttpExchangeImpl x) {
Buf buf = x.input();
Range action = x.verb_().range();
Range path = x.path_().range();
long hash = hash(buf.bytes(), action, path);
synchronized (this) {
SimpleList<Route> candidates = routes.get(hash);
candidates = routes.get(hash);
if (candidates != null) {
for (int i = 0; i < candidates.size(); i++) {
Route route = candidates.get(i);
if (BytesUtil.matches(buf.bytes(), action, route.action, true)
&& BytesUtil.startsWith(buf.bytes(), path, route.path, true)) {
int pos = path.start + route.path.length;
if (path.limit() == pos || buf.get(pos) == '/') {
x.setSubpath(pos, path.limit());
return route.handler;
}
}
}
}
if (genericHandler != null) {
x.setSubpath(path.start, path.limit());
return genericHandler;
}
}
throw x.notFound();
}