mirror of
https://github.com/internetee/epp_proxy.git
synced 2025-08-15 12:03:47 +02:00
Expect user to close connection abruptly
When waiting for input from socket, expect not only a valid outcome, but also the client getting bored and closing the connection without any message being sent.Log an info message when that happens,but do not make it an error. Also, only use hyphens for headers sent to registry server.
This commit is contained in:
parent
bb3a352092
commit
86af6b8f57
1 changed files with 11 additions and 10 deletions
|
@ -124,7 +124,6 @@ read_length(Socket) ->
|
||||||
LengthToReceive = epp_util:frame_length_to_receive(Length),
|
LengthToReceive = epp_util:frame_length_to_receive(Length),
|
||||||
{ok, LengthToReceive};
|
{ok, LengthToReceive};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:error("Error: ~p~n", [Reason]),
|
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -133,7 +132,6 @@ read_frame(Socket, FrameLength) ->
|
||||||
{ok, Data} ->
|
{ok, Data} ->
|
||||||
{ok, Data};
|
{ok, Data};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:error("Error: ~p~n", [Reason]),
|
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -149,31 +147,34 @@ write_line(Socket, Line) ->
|
||||||
|
|
||||||
%% First, listen for 4 bytes, then listen until the declared length.
|
%% First, listen for 4 bytes, then listen until the declared length.
|
||||||
%% Return the frame binary at the very end.
|
%% Return the frame binary at the very end.
|
||||||
|
%% If the client closes connection abruptly, then kill the process
|
||||||
frame_from_socket(Socket, State) ->
|
frame_from_socket(Socket, State) ->
|
||||||
Length = case read_length(Socket) of
|
Length = case read_length(Socket) of
|
||||||
{ok, Data} ->
|
{ok, Data} ->
|
||||||
Data;
|
Data;
|
||||||
{error, _Details} ->
|
{error, closed} ->
|
||||||
{stop, normal, State}
|
log_and_exit(State)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
Frame = case read_frame(Socket, Length) of
|
Frame = case read_frame(Socket, Length) of
|
||||||
{ok, FrameData} ->
|
{ok, FrameData} ->
|
||||||
FrameData;
|
FrameData;
|
||||||
{error, _FrameDetails} ->
|
{error, closed} ->
|
||||||
{stop, normal, State}
|
log_and_exit(State)
|
||||||
end,
|
end,
|
||||||
Frame.
|
Frame.
|
||||||
|
|
||||||
|
log_and_exit(State) ->
|
||||||
|
lager:info("Client closed connection: [~p]~n", [State]),
|
||||||
|
exit(normal).
|
||||||
|
|
||||||
%% Extract state info from socket. Fail if you must.
|
%% Extract state info from socket. Fail if you must.
|
||||||
state_from_socket(Socket, State) ->
|
state_from_socket(Socket, State) ->
|
||||||
{ok, PeerCert} = ssl:peercert(Socket),
|
{ok, PeerCert} = ssl:peercert(Socket),
|
||||||
{ok, {PeerIp, _PeerPort}} = ssl:peername(Socket),
|
{ok, {PeerIp, _PeerPort}} = ssl:peername(Socket),
|
||||||
{SSL_CLIENT_S_DN_CN, SSL_CLIENT_CERT} =
|
{SSL_CLIENT_S_DN_CN, SSL_CLIENT_CERT} =
|
||||||
epp_certs:headers_from_cert(PeerCert),
|
epp_certs:headers_from_cert(PeerCert),
|
||||||
Headers = [{"SSL_CLIENT_CERT", SSL_CLIENT_CERT},
|
Headers = [{"SSL-CLIENT-CERT", SSL_CLIENT_CERT},
|
||||||
{"SSL_CLIENT_S_DN_CN", SSL_CLIENT_S_DN_CN},
|
|
||||||
{"SSL-CLIENT-CERT", SSL_CLIENT_CERT},
|
|
||||||
{"SSL-CLIENT-S-DN-CN", SSL_CLIENT_S_DN_CN},
|
{"SSL-CLIENT-S-DN-CN", SSL_CLIENT_S_DN_CN},
|
||||||
{"User-Agent", <<"EPP proxy">>},
|
{"User-Agent", <<"EPP proxy">>},
|
||||||
{"X-Forwarded-for", epp_util:readable_ip(PeerIp)}],
|
{"X-Forwarded-for", epp_util:readable_ip(PeerIp)}],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue