anchor.diff:      end.
   
   
  -% Parse out redirect URL from response
  +%% get_redirect_url/1
  +%% ====================================================================
  +%% @doc
  +%% Retrieves redirect URL from a HTTP response.
  +%% @end
  +-spec get_redirect_url(string(), list()) -> string().
  +%% ====================================================================
   get_redirect_url(OldURL, Headers) ->
       Location = proplists:get_value("location", Headers),
       case Location of
  
positive.code:     end.
  
  
  % Make the response more readable
  normalise_response({ok, RcodeList, Headers, Body}) ->
      RcodeInt = list_to_integer(RcodeList),
      LowHeaders = [{string:to_lower(K), V} || {K, V} <- Headers],
  
negative.code: %% Internal functions
  %% ====================================================================
  
  %% discover_op_endpoint/1
  %% ====================================================================
  %% @doc
  %% Retrieves an XRDS document from given endpoint URL and parses out the URI which will
  %% be used for OpenID login redirect.
  %% @end
  -spec discover_op_endpoint(string()) -> string().
  %% ====================================================================
  discover_op_endpoint(EndpointURL) ->
      XRDS = get_xrds(EndpointURL),
      {Xml, _} = xmerl_scan:string(XRDS),
      xml_extract_value("URI", Xml).
  
  
  %% xml_extract_value/2
  %% ====================================================================
  %% @doc
  %% Extracts value from under a certain key
  %% @end
  -spec xml_extract_value(string(), #xmlElement{}) -> string().
  %% ====================================================================
  xml_extract_value(KeyName, Xml) ->
      [#xmlElement{content = [#xmlText{value = Value} | _]}] = xmerl_xpath:string("//" ++ KeyName, Xml),
      Value.
  
  
  %% get_xrds/1
  %% ====================================================================
  %% @doc
  %% Downloads an XRDS document from given URL.
  %% @end
  -spec get_xrds(string()) -> string().
  %% ====================================================================
  get_xrds(URL) ->
      % Maximum redirection count = 5
      {ok, 200, _, Body} = get_xrds(URL, 5),
      Body.
  
  % Gets xrds file performing GET on provided URL. Supports redirects.
  get_xrds(URL, Redirects) ->
      ReqHeaders =
          [
              {"Accept", "application/xrds+xml;level=1, */*"},
              {"Connection", "close"}
          ],
      ResponseRaw = ibrowse:send_req(URL, ReqHeaders, get),
      Response = normalise_response(ResponseRaw),
  