Changed ProxyPass
authorAdam Chlipala <adamc@hcoop.net>
Sun, 6 Aug 2006 21:33:32 +0000 (21:33 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sun, 6 Aug 2006 21:33:32 +0000 (21:33 +0000)
configDefault/apache.cfg
configDefault/apache.csg
lib/mod_rewrite.dtl
lib/proxy.dtl
src/plugins/apache.sml
tests/testApache.dtl

index 4977093..06ff92a 100644 (file)
@@ -7,4 +7,7 @@ val confDir = "/home/adamc/fake"
 
 val webNodes = ["this"]
 
 
 val webNodes = ["this"]
 
+val proxyTargets = ["http://hcoop.net/cgi-bin/mailman",
+                   "http://hcoop.net/pipermail"]
+
 end
 end
index 3ade218..dcf989c 100644 (file)
@@ -6,4 +6,6 @@ signature APACHE_CONFIG = sig
 
     val webNodes : string list
 
 
     val webNodes : string list
 
+    val proxyTargets : string list
+
 end
 end
index 7097ec5..a7c363e 100644 (file)
@@ -39,10 +39,24 @@ extern val redirectWith : redirect_code -> mod_rewrite_flag;
 extern val skip : int -> mod_rewrite_flag;
 extern val env : rewrite_arg -> rewrite_arg -> mod_rewrite_flag;
 
 extern val skip : int -> mod_rewrite_flag;
 extern val env : rewrite_arg -> rewrite_arg -> mod_rewrite_flag;
 
+extern type mod_rewrite_cond_flag;
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond">the
+  Apache documentation</a> for information on what these flags mean.}}
+
+extern val cond_nocase : mod_rewrite_cond_flag;
+extern val ornext : mod_rewrite_cond_flag;
+
 extern val rewriteRule : no_spaces -> no_spaces -> [mod_rewrite_flag] -> [Vhost];
 {{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule">Apache
   documentation for <tt>RewriteRule</tt></a>.}}
 
 extern val rewriteRule : no_spaces -> no_spaces -> [mod_rewrite_flag] -> [Vhost];
 {{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule">Apache
   documentation for <tt>RewriteRule</tt></a>.}}
 
+extern val rewriteCond: no_spaces -> no_spaces -> [mod_rewrite_cond_flag] -> [Vhost];
+{{See <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond">Apache
+  documentation for <tt>RewriteCond</tt></a>.}}
+
+extern type proxy_port;
+{{A port number above 1024}}
+
 extern val localProxyRewrite : no_spaces -> no_spaces -> proxy_port -> [Vhost];
 {{All requests matching the regular expression in the first argument are
   redirected to another HTTPD running on localhost at the given port, generating
 extern val localProxyRewrite : no_spaces -> no_spaces -> proxy_port -> [Vhost];
 {{All requests matching the regular expression in the first argument are
   redirected to another HTTPD running on localhost at the given port, generating
dissimilarity index 87%
index bc487a5..713fe6a 100644 (file)
@@ -1,10 +1,8 @@
-extern type proxy_port;
-{{A port number above 1024}}
-
-extern val localProxyPass : no_spaces -> no_spaces -> proxy_port -> [Vhost];
-extern val localProxyPassReverse : no_spaces -> no_spaces -> proxy_port -> [Vhost];
-{{Interface to Apache <tt>ProxyPass</tt> and <tt>LocalProxyPass</tt> for
-  proxying to localhost only. The arguments give:
-  <li> The URL prefix to treat as proxied</li>
-  <li> The corresponding URL prefix on the other local server</li>
-  <li> The port number of the local server</li>}}
+extern type proxy_target;
+{{URL prefix designating where to send proxied requests.
+  It can be any localhost URL on a port of at least 1024.
+  In addition, other allowed targets can be configured.}}
+
+extern val proxyPass : no_spaces -> proxy_target -> [Vhost];
+extern val proxyPassReverse : no_spaces -> proxy_target -> [Vhost];
+{{Interface to Apache <tt>ProxyPass</tt> and <tt>LocalProxyPass</tt>}}
index faa2c65..a959023 100644 (file)
@@ -24,7 +24,24 @@ open Ast
 
 val _ = Env.type_one "proxy_port"
        Env.int
 
 val _ = Env.type_one "proxy_port"
        Env.int
-       (fn n => n >= 1024)
+       (fn n => n > 1024)
+
+val _ = Env.type_one "proxy_target"
+       Env.string
+       (fn s =>
+           let
+               fun default () = List.exists (fn s' => s = s') Config.Apache.proxyTargets
+           in
+               case String.fields (fn ch => ch = #":") s of
+                   ["http", "//localhost", rest] =>
+                   (case String.fields (fn ch => ch = #"/") rest of
+                        port :: _ =>
+                        (case Int.fromString port of
+                             NONE => default ()
+                           | SOME n => n > 1024 orelse default ())
+                      | _ => default ())
+                 | _ => default ()
+           end)
 
 val _ = Env.type_one "rewrite_arg"
        Env.string
 
 val _ = Env.type_one "rewrite_arg"
        Env.string
@@ -93,6 +110,10 @@ val flag = fn (EVar "redirect", _) => SOME "R"
 
            | _ => NONE
 
 
            | _ => NONE
 
+val cond_flag = fn (EVar "cond_nocase", _) => SOME "NC"
+           | (EVar "ornext", _) => SOME "OR"
+           | _ => NONE
+
 
 val vhostsChanged = ref false
 
 
 val vhostsChanged = ref false
 
@@ -202,45 +223,23 @@ val () = Env.action_three "localProxyRewrite"
              write to;
              write " [P]\n"))
 
              write to;
              write " [P]\n"))
 
-val () = Env.action_three "localProxyPass"
-        ("from", Env.string, "to", Env.string, "port", Env.int)
-        (fn (from, to, port) =>
-            let
-                val to =
-                    case to of
-                        "" => "/"
-                      | _ => if String.sub (to, 0) = #"/" then
-                                 to
-                             else
-                                 "/" ^ to
-            in
-                write "\tProxyPass\t";
-                write from;
-                write "\thttp://localhost:";
-                write (Int.toString port);
-                write to;
-                write "\n"
-            end)
-
-val () = Env.action_three "localProxyPassReverse"
-        ("from", Env.string, "to", Env.string, "port", Env.int)
-        (fn (from, to, port) =>
-            let
-                val to =
-                    case to of
-                        "" => "/"
-                      | _ => if String.sub (to, 0) = #"/" then
-                                 to
-                             else
-                                 "/" ^ to
-            in
-                write "\tProxyPassReverse\t";
-                write from;
-                write "\thttp://localhost:";
-                write (Int.toString port);
-                write to;
-                write "\n"
-            end)
+val () = Env.action_two "proxyPass"
+        ("from", Env.string, "to", Env.string)
+        (fn (from, to) =>
+                (write "\tProxyPass\t";
+                 write from;
+                 write "\t";
+                 write to;
+                 write "\n"))
+
+val () = Env.action_two "proxyPassReverse"
+        ("from", Env.string, "to", Env.string)
+        (fn (from, to) =>
+                (write "\tProxyPassReverse\t";
+                 write from;
+                 write "\t";
+                 write to;
+                 write "\n"))
 
 val () = Env.action_three "rewriteRule"
         ("from", Env.string, "to", Env.string, "flags", Env.list flag)
 
 val () = Env.action_three "rewriteRule"
         ("from", Env.string, "to", Env.string, "flags", Env.list flag)
@@ -259,4 +258,21 @@ val () = Env.action_three "rewriteRule"
                                 write "]");
              write "\n"))
 
                                 write "]");
              write "\n"))
 
+val () = Env.action_three "rewriteCond"
+        ("test", Env.string, "pattern", Env.string, "flags", Env.list cond_flag)
+        (fn (from, to, flags) =>
+            (checkRewrite ();
+             write "\tRewriteCond\t";
+             write from;
+             write "\t";
+             write to;
+             case flags of
+                 [] => ()
+               | flag::rest => (write " [";
+                                write flag;
+                                app (fn flag => (write ",";
+                                                 write flag)) rest;
+                                write "]");
+             write "\n"))
+
 end
 end
index 3cee61d..13cbed3 100644 (file)
@@ -13,12 +13,16 @@ domain "hcoop.net" with
                SSL = true
        with
                localProxyRewrite "^/(.*)$" "$1" 6666;
                SSL = true
        with
                localProxyRewrite "^/(.*)$" "$1" 6666;
-               rewriteRule "^/foo.html" "/bar.html" [redirectWith redir300, nosubreq]
+               rewriteCond "hi" "there" [ornext];
+               rewriteRule "^/foo.html" "/bar.html" [redirectWith redir300, nosubreq];
        end;
 
        vhost "proxy" with
        end;
 
        vhost "proxy" with
-               localProxyPass "/proxyLand" "/otherProxyLand" 1234;
-               localProxyPassReverse "/proxyLand" "/otherProxyLand" 1234
-       end
+               proxyPass "/proxyLand" "http://localhost:1234/otherProxyLand";
+               proxyPassReverse "/proxyLand" "http://localhost:1234/otherProxyLand";
+       end;
 
 
+       vhost "lists" with
+               proxyPass "/mailman" "http://hcoop.net/cgi-bin/mailman";
+       end
 end
 end