1. Benoit Chesneau
  2. webmachine

Commits

benoitc  committed 919a956

add better support for cname. Since we want a.b.example.com eventually match to
[cname, "example", "com"] where cname = "a.b" .

  • Participants
  • Parent commits 671f2a3
  • Branches vhost

Comments (0)

Files changed (1)

File src/webmachine_dispatcher.erl

View file
 		     true -> 1;
 		     _ -> 0
 		 end,
-	case try_binding_host(DispatchList, [], [], HostNameParts) of
+	dispatch1(HostNameParts, DispatchList, Path, ExtraDepth, length(HostNameParts)).
+	
+            
+dispatch1(HostNameParts, DispatchList, Path, ExtraDepth, HostDepth) ->
+    case try_binding_host(DispatchList, [], [], HostNameParts) of
 	    no_host_match ->
-            try_binding(DispatchList, Path, ExtraDepth);
+	        if
+	            HostDepth < 2 -> 
+                    try_binding(DispatchList, Path, ExtraDepth);
+                true ->
+                    {HostRest, NewCName} = lists:split(2, HostNameParts),
+                    HostNameParts1 = lists:append(HostRest, [string:join(lists:reverse(NewCName), ".")]),
+                    dispatch1(HostNameParts1, DispatchList, Path, ExtraDepth, HostDepth-1)
+            end;
         {DispatchList1, Bindings} ->
-            case try_binding(DispatchList1, Path, ExtraDepth) of
+            case try_binding(lists:reverse(DispatchList1), Path, ExtraDepth) of
                 {no_dispatch_match, _UnmatchedPathTokens} ->
                     case try_binding(DispatchList, Path, ExtraDepth) of
                         {Mod, ModOpts, PathTokens, Bindings1, AppRoot, StringPath} ->
                     {Mod, ModOpts, PathTokens, Bindings ++ Bindings1, AppRoot, StringPath}
             end
     end.
-            
 
 %% @type matchterm() = {[pathterm()], matchmod(), matchopts()}.
 % The dispatch configuration is a list of these terms, and the