package io.tetrapod.core.web;

import io.tetrapod.protocol.core.WebRoute;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WebRoutes {

   private final Map<String,WebRoute> routes = new ConcurrentHashMap<>();
   
   public void setRoute(String path, int contractId, int structId) {
      // "/api/LoginRequest  contractId=2, structId=1244334
      WebRoute r = new WebRoute(path, structId, contractId);
      routes.put(path, r);
   }
   
   public WebRoute findRoute(String uri) {
      int ix = uri.indexOf('?');
      String path = ix < 0 ? uri : uri.substring(0, ix);
      WebRoute r = routes.get(path);
      if (r == null) {
         // allow /route/params instead of /route?params
         ix = uri.lastIndexOf('/');
         path = ix < 0 ? uri : uri.substring(0, ix);
         r = routes.get(path);
      }
      return r;
   }
   

}

@@ -201,16 +201,17 @@
 %3CString,
+ 
 WebRoute
@@ -249,19 +249,16 @@
 p%3C%3E();%0D%0A
-   
 %0D%0A   pub
@@ -478,21 +478,18 @@
 %0D%0A   %7D%0D%0A
-   
 %0D%0A
+
    publi
@@ -612,24 +612,28 @@
 ng(0, ix);%0D%0A
+%0D%0A%0D%0A
       WebRou
@@ -648,32 +648,276 @@
 outes.get(path);
+ %0D%0A      if (r == null) %7B%0D%0A         // special handling for @root paths%0D%0A         for (WebRoute route : routes.values()) %7B%0D%0A            if (path.startsWith(route.path)) %7B%0D%0A               return route;%0D%0A            %7D%0D%0A         %7D%0D%0A      %7D%0D%0A      
 %0D%0A      if (r ==
@@ -1137,18 +1137,13 @@
 r;%0D%0A
+
    %7D%0D
-%0A   %0D
 %0A%0D%0A%7D

Add handling to @root WebRoute matching so we can send the whole subpath