anchor.diff:  
   -export([start_link/0, init/1, handle_call/3, handle_info/2, handle_cast/2]).
   -export([code_change/3, terminate/2]).
  --export([match_vhost/1]).
  +-export([match_vhost/1, urlsplit_netloc/2]).
   -export([redirect_to_vhost/2]).
   
   -include("couch_db.hrl").
  
positive.code:     bind_vhost(Rest, RestHost, Bindings);
  bind_vhost(_, _, _) -> fail.
  
  % utilities
  
  
  %% create vhost list from ini
  make_vhosts() ->
      lists:foldl(fun({Vhost, Path}, Acc) ->
          {H, P} = split_host_port(Vhost),
          H1 = make_spec(H, []),
          [{{H1,P}, split_path(Path)}|Acc]
      end, [], couch_config:get("vhosts")).
  
  
  split_host_port(HostAsString) ->
      case string:rchr(HostAsString, $:) of
  
negative.code: 
  %% bind host
  %% first it try to bind the port then the hostname.
  try_bind_vhost([], _HostParts, _Port, _PathParts) ->
      no_vhost_matched;
  try_bind_vhost([VhostSpec|Rest], HostParts, Port, PathParts) ->
      {{VHostParts, VPort, VPath}, Path} = VhostSpec,
      case bind_port(VPort, Port) of
          ok -> 
              case bind_vhost(lists:reverse(VHostParts), HostParts, []) of
                  {ok, Bindings, Remainings} ->
                      case bind_path(VPath, PathParts) of
                          {ok, PathParts1} ->
                              Path1 = make_target(Path, Bindings, Remainings, []),
                              {make_path(Path1), make_path(PathParts1)};
                          fail -> 
                              try_bind_vhost(Rest, HostParts, Port,
                                  PathParts)
                      end;
                  fail -> try_bind_vhost(Rest, HostParts, Port, PathParts)
              end;
          fail ->  try_bind_vhost(Rest, HostParts, Port, PathParts)
      end.
  
  %% doc: build new patch from bindings. bindings are query args
  