anchor.diff:  -include_lib("public_key/include/public_key.hrl").
   -include("veil_modules/control_panel/common.hrl").
   -include("err.hrl").
  --include("veil_modules/control_panel/connection_check_values.hrl").
   
   -record(state, {
       version = <<"latest">> :: binary(),
  
positive.code:     process_callback_answer(Answer, Req2).
  
  
  %% do_init/1
  %% ====================================================================
  %% Initializes request context, without peer validation
  %% @end
  -spec do_init(req()) -> {ok, req(), #state{} | {error, term()}}.
  %% ====================================================================
  do_init(Req) ->
      Req2 = gui_utils:cowboy_ensure_header(<<"content-type">>, <<"application/json">>, Req),
      {PathInfo, _} = cowboy_req:path_info(Req2),
      case rest_routes:route(PathInfo) of
          undefined ->
              {ok, Req2, {error, path_invalid}};
          {Module, Id} ->
              {Method, _} = cowboy_req:method(Req2),
              {Version, _} = cowboy_req:binding(version, Req2), % :version in cowboy router
              Req3 = cowboy_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req2),
              {ok, Req3, #state{version = Version, handler_module = Module, method = Method, resource_id = Id}}
      end.
  %% do_init/2
  %% ====================================================================
  %% Initializes request context after the peer has been validated. Checks if user
  
negative.code:         {ok, _} ->
              fslogic_context:set_user_dn(DnString),
              ?info("[REST] Peer connected using certificate with subject: ~p ~n", [DnString]),
              {PathInfo, _} = cowboy_req:path_info(Req2),
              case rest_routes:route(PathInfo) of
                  undefined ->
                      {ok, Req2, {error, path_invalid}};
                  {Module, Id} ->
                      {Method, _} = cowboy_req:method(Req2),
                      {Version, _} = cowboy_req:binding(version, Req2), % :version in cowboy router
                      Req3 = cowboy_req:set_resp_header(<<"Access-Control-Allow-Origin">>, <<"*">>, Req2),
                      {ok, Req3, #state{version = Version, handler_module = Module, method = Method, resource_id = Id}}
              end;
          _ ->
              {ok, Req2, {error, {user_unknown, DnString}}}
      end.
  