Commits

Anonymous committed e20f375

Some more experiments

Comments (0)

Files changed (1)

     {ok, Pid} = 
         inets:start(httpd, 
                     [{port, ?DEFAULT_PORT},
-                     {server_name, "ehttp"},
+                     {server_name, "localhost"},
                      {server_root, CWD},
                      {document_root, CWD},
 %                     {script, {"GET", "hgwebdir.cgi"}},
     inets:stop(httpd, Pid).
 
 do(Info) ->
+    try dodo(Info)
+    catch _:Err -> io:format("Err(~p): ~p~n", [Err, erlang:get_stacktrace()]) end.
+
+dodo(Info) ->
     case proplists:get_value(status, Info#mod.data) of
         %% A status code has been generated!
         {_StatusCode, _PhraseArgs, _Reason} ->
                     Path = Info#mod.request_uri,
                     case re:run(Path, "hgweb.cgi", []) of
                         {match,_} -> 
-                            NewPath = do_rewrite(Path),
-                            {proceed, [{new_request_uri, NewPath}
-                                       | Info#mod.data]};
+                            io:format("Path=~p~n",[Path]),
+                            case do_rewrite(Path) of
+                                Path ->
+                                    io:format("No new Path=~p~n",[Path]),
+                                    {proceed, Info#mod.data};
+                                NewPath ->
+                                    io:format("NewPath=~p~n",[NewPath]),
+                                    ServerName = httpd_util:lookup(Info#mod.config_db, server_name),
+                                    io:format("ServerName=~p~n",[ServerName]),
+                                    URL = "http://" ++ ServerName ++ ":" ++ i2l(?DEFAULT_PORT) ++ NewPath,
+                                    io:format("URL=~p~n",[URL]),
+                                    ReasonPhrase = httpd_util:reason_phrase(301),
+                                    Message = httpd_util:message(301, URL, Info#mod.config_db),
+                                    {proceed,
+                                     [{response, {301, 
+                                                  ["Location: ", URL, "\r\n",
+                                                   "Content-Type: text/html\r\n",
+                                                   "\r\n",
+                                                   "<HTML>\n<HEAD>\n<TITLE>",ReasonPhrase,
+                                                   "</TITLE>\n</HEAD>\n"
+                                                   "<BODY>\n<H1>",ReasonPhrase,
+                                                   "</H1>\n", Message, 
+                                                   "\n</BODY>\n</HTML>\n"]}}
+                                      | Info#mod.data]}
+                            end;
                         _ ->
                             {proceed, Info#mod.data} 
                     end
                 ,fun branches_rewrite/1
                 ,fun graph_rewrite/1
                 ,fun tags_rewrite/1
+                ,fun shortlog_rewrite/1
                 ]).
 
 do_rewrite(Path, [])     -> Path;
     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]).
 
+shortlog_rewrite(Path) ->
+    re:replace(Path, 
+               "(.*hgweb.cgi)(.*)(/shortlog)(.*)", 
+               "\\1\\4", 
+               [{return, list}, global]).
+
+
+i2l(I) when is_integer(I) -> integer_to_list(I).
+
+