anchor.diff:  %%                                  {stop, Reason, State}
   %% @doc Load a new set of dispatch rules.
   handle_cast({set_dispatch_rules, Rules}, State) ->
  -    {noreply, State#state{rules=Rules}};
  +    {noreply, State#state{rules=compile_regexps_hosts(Rules)}};
   
   %% @doc Trap unknown casts
   handle_cast(Message, State) ->
  
positive.code: -define(SEPARATOR, $\/).
  -define(MATCH_ALL, '*').
  
  %% @spec dispatch(Path::string(), DispatchList::[matchterm()]) ->
  %%                                            dispterm() | dispfail()
  %% @doc Interface for URL dispatching.
  %% See also http://bitbucket.org/justin/webmachine/wiki/DispatchConfiguration
  dispatch(PathAsString, DispatchList) ->
      Path = string:tokens(PathAsString, [?SEPARATOR]),
      % URIs that end with a trailing slash are implicitly one token
      % "deeper" than we otherwise might think as we are "inside"
  
negative.code: is_hostname(_) -> true.
  
  
  %% @doc Compile all regexps in the dispatch lists
  compile_regexps_hosts(DLs) ->
      compile_regexps_hosts(DLs, []).
  
  compile_regexps_hosts([], Acc) ->
      lists:reverse(Acc);
  compile_regexps_hosts([#wm_host_dispatch_list{dispatch_list=DispatchList} = DL|Rest], Acc) ->
      DispatchList1 = compile_regexps(DispatchList, []),
      compile_regexps_hosts(Rest, [DL#wm_host_dispatch_list{dispatch_list=DispatchList1}|Acc]).
  
  compile_regexps([], Acc) ->
      lists:reverse(Acc);
  compile_regexps([{DispatchName, PathSchema, Mod, Props}|Rest], Acc) ->
      PathSchema1 = compile_re_path(PathSchema, []),
      compile_regexps(Rest, [{DispatchName, PathSchema1, Mod, Props}|Acc]).
  
  compile_re_path([], Acc) ->
      lists:reverse(Acc);
  compile_re_path([{Token, {Mod, Fun}}|Rest], Acc) ->
      compile_re_path(Rest, [{Token, {Mod,Fun}}|Acc]);
  compile_re_path([{Token, RE}|Rest], Acc) ->
      {ok, MP} = re:compile(RE),
      compile_re_path(Rest, [{Token, MP}|Acc]);
  compile_re_path([{Token, RE, Options}|Rest], Acc) ->
      {ok, MP} = re:compile(RE, re_filter(Options, [])),
      compile_re_path(Rest, [{Token, MP, Options}|Acc]);
  compile_re_path([Token|Rest], Acc) ->
      compile_re_path(Rest, [Token|Acc]).
  
      %% Only allow options valid for the re:compile/3 function.
      re_filter([], Acc) ->
          lists:reverse(Acc);
      re_filter([unicode|Options], Acc) ->
          re_filter(Options, [unicode|Acc]);
      re_filter([anchored|Options], Acc) ->
          re_filter(Options, [anchored|Acc]);
      re_filter([caseless|Options], Acc) ->
          re_filter(Options, [caseless|Acc]);
      re_filter([dotall|Options], Acc) ->
          re_filter(Options, [dotall|Acc]);
      re_filter([extended|Options], Acc) ->
          re_filter(Options, [extended|Acc]);
      re_filter([ungreedy|Options], Acc) ->
          re_filter(Options, [ungreedy|Acc]);
      re_filter([no_auto_capture|Options], Acc) ->
          re_filter(Options, [no_auto_capture|Acc]);
      re_filter([dupnames|Options], Acc) ->
          re_filter(Options, [dupnames|Acc]);
      re_filter([_|Options], Acc) ->
          re_filter(Options, Acc).
  
  
  
  %%%%%%% Adapted version of Webmachine dispatcher %%%%%%%%
  % Main difference is that we want to know which dispatch rule was choosen.
  % We also added check functions and regular expressions to match vars.
  
  %% @author Robert Ahrens <rahrens@basho.com>
  %% @author Justin Sheehy <justin@basho.com>
  