anchor.diff:      end.
   
   %%--------------------------------------------------------------------
  -handle_req_map(ReqMap, RespHdrs, S) ->
  +handle_req_map(ReqMap, RespHdrs, #?S{stream=Stream}=S) ->
       %% TODO: maybe validate the request JSON, but could be lots of work for
       %% little reward
       %% validate_aps_json(ReqMap)
  
positive.code: -spec on_receive_request_headers(Headers, State) -> Result when
        Headers :: h2_headers(), State :: state(), Result :: {ok, state()}.
  on_receive_request_headers(Headers, #?S{req=Req, stream=Strm}=State) ->
      lager:info("~p:on_receive_request_headers(~p, ~p)",
                 [?MODULE, Headers, Req]),
      {ok, PeerCertDer} = h2_connection:get_peercert(Strm#stream.conn_pid),
      PeerCert = apns_cert:der_decode_cert(PeerCertDer),
      PeerCertInfo = apns_cert:get_cert_info_map(PeerCert),
      {ok, State#?S{req=Req#req{headers=Headers}, peercert=PeerCertInfo}}.
  
  %%--------------------------------------------------------------------
  on_send_push_promise(Headers, #?S{req=Req}=State) ->
      lager:info("~p:on_send_push_promise(~p, ~p)", [Headers, Req]),
      {ok, State#?S{req=Req#req{headers=Headers}}}.
  
  %%--------------------------------------------------------------------
  on_receive_request_data(Bin, #?S{req=Req}=State)->
      lager:info("~p:on_receive_request_data(~p, ~p)",
                 [?MODULE, Bin, Req]),
      {ok, State#?S{req=Req#req{data=Bin}}}.
  
  %%--------------------------------------------------------------------
  on_request_end_stream(#?S{stream=Stream, req=Req} = State) ->
      lager:info("~p:on_request_end_stream(~p)", [?MODULE, [Stream, Req]]),
      Headers = Req#req.headers,
      Method = proplists:get_value(<<":method">>, Headers),
      Path = binary_to_list(proplists:get_value(<<":path">>, Headers)),
  
      lager:debug("[~p:~p:~p] ~s ~s",
                  [?MODULE, self(), Stream#stream.id, Method, Path]),
  
      handle_request(Method, Path, Headers, State),
  
negative.code:         Ms when is_integer(Ms), Ms =< 0 ->
              ok;
          Ms when is_integer(Ms) ->
              lager:info("[~p:handle_req_map:~p][StrId:~B] Delaying for ~B ms",
                         [?MODULE, self(), Stream#stream.id, Delay]),
              receive after Ms -> ok end
      end,
      Response.
  