From e95a129e304463e78a1e6ebce097a371e048ecc2 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 6 Aug 2006 21:33:32 +0000 Subject: [PATCH] Changed ProxyPass --- configDefault/apache.cfg | 3 ++ configDefault/apache.csg | 2 + lib/mod_rewrite.dtl | 14 ++++++ lib/proxy.dtl | 18 ++++---- src/plugins/apache.sml | 96 +++++++++++++++++++++++----------------- tests/testApache.dtl | 12 +++-- 6 files changed, 91 insertions(+), 54 deletions(-) rewrite lib/proxy.dtl (87%) diff --git a/configDefault/apache.cfg b/configDefault/apache.cfg index 4977093..06ff92a 100644 --- a/configDefault/apache.cfg +++ b/configDefault/apache.cfg @@ -7,4 +7,7 @@ val confDir = "/home/adamc/fake" val webNodes = ["this"] +val proxyTargets = ["http://hcoop.net/cgi-bin/mailman", + "http://hcoop.net/pipermail"] + end diff --git a/configDefault/apache.csg b/configDefault/apache.csg index 3ade218..dcf989c 100644 --- a/configDefault/apache.csg +++ b/configDefault/apache.csg @@ -6,4 +6,6 @@ signature APACHE_CONFIG = sig val webNodes : string list + val proxyTargets : string list + end diff --git a/lib/mod_rewrite.dtl b/lib/mod_rewrite.dtl index 7097ec5..a7c363e 100644 --- a/lib/mod_rewrite.dtl +++ b/lib/mod_rewrite.dtl @@ -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 type mod_rewrite_cond_flag; +{{See the + Apache documentation 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 Apache documentation for RewriteRule.}} +extern val rewriteCond: no_spaces -> no_spaces -> [mod_rewrite_cond_flag] -> [Vhost]; +{{See Apache + documentation for RewriteCond.}} + +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 diff --git a/lib/proxy.dtl b/lib/proxy.dtl dissimilarity index 87% index bc487a5..713fe6a 100644 --- a/lib/proxy.dtl +++ b/lib/proxy.dtl @@ -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 ProxyPass and LocalProxyPass for - proxying to localhost only. The arguments give: -
  • The URL prefix to treat as proxied
  • -
  • The corresponding URL prefix on the other local server
  • -
  • The port number of the local server
  • }} +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 ProxyPass and LocalProxyPass}} diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index faa2c65..a959023 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -24,7 +24,24 @@ open Ast 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 @@ -93,6 +110,10 @@ val flag = fn (EVar "redirect", _) => SOME "R" | _ => NONE +val cond_flag = fn (EVar "cond_nocase", _) => SOME "NC" + | (EVar "ornext", _) => SOME "OR" + | _ => NONE + val vhostsChanged = ref false @@ -202,45 +223,23 @@ val () = Env.action_three "localProxyRewrite" 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) @@ -259,4 +258,21 @@ val () = Env.action_three "rewriteRule" 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 diff --git a/tests/testApache.dtl b/tests/testApache.dtl index 3cee61d..13cbed3 100644 --- a/tests/testApache.dtl +++ b/tests/testApache.dtl @@ -13,12 +13,16 @@ domain "hcoop.net" with 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 - 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 -- 2.20.1