Commits

Anonymous committed 4a09110

Adding some experimental URI rewrites.

  • Participants
  • Parent commits dfcc534

Comments (0)

Files changed (1)

                     Path = Info#mod.request_uri,
                     case re:run(Path, "hgweb.cgi", []) of
                         {match,_} -> 
-                            NewPath = re:replace(Path, 
-                                                 "(.*hgweb.cgi)(.*)(/static.*)", 
-                                                 "\\1\\3", 
-                                                 [{return, list}, global]),
+                            NewPath = do_rewrite(Path),
                             {proceed, [{new_request_uri, NewPath}
                                        | Info#mod.data]};
                         _ ->
     end.
 	
 
+do_rewrite(Path) ->
+    do_rewrite(Path,
+               [fun static_rewrite/1
+                ,fun branches_rewrite/1
+                ,fun graph_rewrite/1
+                ,fun tags_rewrite/1
+                ]).
+
+do_rewrite(Path, [])     -> Path;
+do_rewrite(Path, [F|Fs]) ->
+    case F(Path) of
+        Path    -> do_rewrite(Path, Fs);
+        NewPath -> NewPath
+    end.
+
+static_rewrite(Path) ->
+    io:format("static: ~p~n",[Path]),
+    re:replace(Path, 
+               "(.*hgweb.cgi)(.*)(/static.*)", 
+               "\\1\\3", 
+               [{return, list}, global]).
+
+branches_rewrite(Path) ->
+    io:format("branches: ~p~n",[Path]),
+    re:replace(Path, 
+               "(.*hgweb.cgi)(.*)(/branches.*)", 
+               "\\1\\3", 
+               [{return, list}, global]).
+
+graph_rewrite(Path) ->
+    io:format("graph: ~p~n",[Path]),
+    re:replace(Path, 
+               "(.*hgweb.cgi)(.*)(/graph.*)", 
+               "\\1\\3", 
+               [{return, list}, global]).
+
+tags_rewrite(Path) ->
+    io:format("tags: ~p~n",[Path]),
+    re:replace(Path, 
+               "(.*hgweb.cgi)(.*)(/tags.*)", 
+               "\\1\\3", 
+               [{return, list}, global]).
+