Support ! as a ProxyPass target
authorClinton Ebadi <clinton@unknownlamer.org>
Tue, 25 Nov 2014 01:24:21 +0000 (20:24 -0500)
committerClinton Ebadi <clinton@unknownlamer.org>
Tue, 25 Nov 2014 01:24:21 +0000 (20:24 -0500)
Reported by notd, ProxyPass can take ! to indicate not to proxy
anything under a path. Split proxy_target and proxy_reverse_target
types since ProxyPassReverse does not allow ! as a target.

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

index 713fe6a..272d83b 100644 (file)
@@ -4,5 +4,5 @@ extern type proxy_target;
   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>}}
+extern val proxyPassReverse : no_spaces -> proxy_reverse_target -> [Vhost];
+{{Interface to Apache <tt>ProxyPass</tt> and <tt>ProxyPassReverse</tt>}}
index 29fdf05..e160745 100644 (file)
@@ -62,32 +62,34 @@ val _ = Env.type_one "proxy_port"
        Env.int
        (fn n => n > 1024)
 
+fun validProxyTarget default s =
+    case String.fields (fn ch => ch = #":") s of
+       "http" :: host :: rest =>
+       let
+           val rest = String.concatWith ":" rest
+       in
+           if List.exists (fn h' => host = h') (map (fn h => String.concat ["//", h]) Config.Apache.proxyHosts)
+           then
+               CharVector.all (fn ch => Char.isPrint ch andalso not (Char.isSpace ch)
+                                        andalso ch <> #"\"" andalso ch <> #"'") rest
+               andalso case String.fields (fn ch => ch = #"/") rest of
+                           port :: _ =>
+                           (case Int.fromString port of
+                                NONE => default s
+                              | SOME n => n > 1024 orelse default s)
+                         | _ => default s
+           else
+               default s
+       end
+      | _ => default s
+
 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" :: host :: rest =>
-                   let
-                       val rest = String.concatWith ":" rest
-                   in
-                       if List.exists (fn h' => host = h') (map (fn h => String.concat ["//", h]) Config.Apache.proxyHosts)
-                       then
-                           CharVector.all (fn ch => Char.isPrint ch andalso not (Char.isSpace ch)
-                                                    andalso ch <> #"\"" andalso ch <> #"'") rest
-                           andalso case String.fields (fn ch => ch = #"/") rest of
-                                       port :: _ =>
-                                       (case Int.fromString port of
-                                            NONE => default ()
-                                          | SOME n => n > 1024 orelse default ())
-                                     | _ => default ()
-                       else
-                           default ()
-                   end
-                 | _ => default ()
-           end)
+       (validProxyTarget (fn s => List.exists (fn s' => s = s') (Config.Apache.proxyTargets @ ["!"])))
+
+val _ = Env.type_one "proxy_reverse_target"
+       Env.string
+       (validProxyTarget (fn s => List.exists (fn s' => s = s') Config.Apache.proxyTargets))
 
 val _ = Env.type_one "rewrite_arg"
        Env.string