apache: generalize localProxyRewrite into proxyRewrite release_20190427
authorClinton Ebadi <clinton@unknownlamer.org>
Sat, 27 Apr 2019 22:48:52 +0000 (18:48 -0400)
committerClinton Ebadi <clinton@unknownlamer.org>
Sat, 27 Apr 2019 22:48:52 +0000 (18:48 -0400)
Allow use of any proxy target instead of localhost (which has not had
any use at hcoop for several years since we moved member logins/daemon
to a server separate from apache), and allow passing rewrite
flags. Apache will accept any combination of rewrite flags, despite
all combinations not making any sense.

lib/mod_rewrite.dtl
src/plugins/apache.sml

index ce0436c..b4255dc 100644 (file)
@@ -63,11 +63,12 @@ extern val rewriteBase : no_spaces -> [Location];
 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
-  the new URI by substituting variables in the second argument as per Apache
-  mod_rewrite.}}
+extern val proxyRewrite : regexp -> proxy_reverse_target -> no_spaces -> [mod_rewrite_flag] -> [^Vhost];
+{{Safe wrapper around mod_rewrite proxy flag. All requests matching
+  the regular expression in the first argument are proxied to the host
+  specified in the second argument, appending a new URI by
+  substituting variables in the third argument as per Apache
+  mod_rewrite. Additional rewrite flags may be specified.}}
 
 extern type mod_rewrite_trace_level;
 {{A mod_rewrite log level, between 0 and 8. 2 or 3 are useful for
index f21d3ac..a490419 100644 (file)
@@ -664,17 +664,26 @@ fun checkExpires () =
        (write "\tExpiresActive on\n";
         expiresEnabled := true)
 
-val () = Env.action_three "localProxyRewrite"
-        ("from", Env.string, "to", Env.string, "port", Env.int)
-        (fn (from, to, port) =>
+val () = Env.action_four "proxyRewrite"
+        ("from", Env.string, "tohost", Env.string, "to", Env.string, "flags", Env.list flag)
+        (fn (from, tohost, to, flags) =>
             (checkRewrite ();
              write "\tRewriteRule\t\"";
              write from;
-             write "\"\thttp://localhost:";
-             write (Int.toString port);
-             write "/";
+             write "\"\t\"";
+             write tohost;
+             write "/"; (* ensure rewrite rule can't change port *)
              write to;
-             write " [P]\n"))
+             write "\"";
+             write " [P";
+             case flags of
+                 [] => ()
+               | flag::rest => (write ",";
+                                write flag;
+                                app (fn flag => (write ",";
+                                                 write flag)) rest);
+
+             write "]\n"))
 
 val () = Env.action_four "expiresByType"
         ("mime", Env.string, "base", interval_base, "num", Env.int, "inter", interval)