Skip to content

Commit

Permalink
Add h2_connection:get_peercert/1
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwin Fine committed Sep 1, 2016
1 parent 9bd45ff commit 049f3f3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/h2_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
send_promise/4,
get_response/2,
get_peer/1,
get_peercert/1,
get_streams/1,
send_window_update/2,
send_frame/2
Expand Down Expand Up @@ -226,6 +227,11 @@ send_body(Pid, StreamId, Body, Opts) ->
get_peer(Pid) ->
gen_fsm:sync_send_all_state_event(Pid, get_peer).

-spec get_peercert(pid()) ->
{ok, binary()} | {error, term()}.
get_peercert(Pid) ->
gen_fsm:sync_send_all_state_event(Pid, get_peercert).

-spec is_push(pid()) -> boolean().
is_push(Pid) ->
gen_fsm:sync_send_all_state_event(Pid, is_push).
Expand Down Expand Up @@ -1084,6 +1090,18 @@ handle_sync_event(get_peer, _F, StateName,
{ok, _AddrPort}=OK ->
{reply, OK, StateName, Conn}
end;
handle_sync_event(get_peercert, _F, StateName,
#connection{
socket={Transport,_}=Socket
}=Conn) ->
case sock:peercert(Socket) of
{error, _}=Error ->
lager:warning("failed to fetch peer cert for ~p socket",
[Transport]),
{reply, Error, StateName, Conn};
{ok, _Cert}=OK ->
{reply, OK, StateName, Conn}
end;
handle_sync_event(_E, _F, StateName,
#connection{}=Conn) ->
{next_state, StateName, Conn}.
Expand Down

0 comments on commit 049f3f3

Please sign in to comment.