Merge remote-tracking branch 'cloudant/3318-bypass-vhosts'
diff --git a/src/couch_httpd_vhost.erl b/src/couch_httpd_vhost.erl
index 91a2476..f23f41d 100644
--- a/src/couch_httpd_vhost.erl
+++ b/src/couch_httpd_vhost.erl
@@ -96,6 +96,14 @@
 %% @doc Try to find a rule matching current Host heade. some rule is
 %% found it rewrite the Mochiweb Request else it return current Request.
 dispatch_host(MochiReq) ->
+    case vhost_enabled() of
+        true ->
+            dispatch_host_int(MochiReq);
+        false ->
+            MochiReq
+    end.
+
+dispatch_host_int(MochiReq) ->
     #vhosts_state{
         vhost_globals = VHostGlobals,
         vhosts = VHosts,
@@ -398,3 +406,14 @@
             "redirect_vhost_handler", DefaultVHostFun)),
 
     {VHostGlobals, VHosts, Fun}.
+
+%% cheaply determine if there are any virtual hosts
+%% configured at all.
+vhost_enabled() ->
+    case {config:get("httpd", "vhost_global_handlers"),
+          config:get("vhosts")} of
+        {undefined, []} ->
+            false;
+        _ ->
+            true
+    end.