Move epp_record into a header file

This commit is contained in:
Maciej Szlosarczyk 2019-05-28 11:05:51 +03:00
parent 6ef2b881f8
commit c74bacfee3
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
3 changed files with 29 additions and 18 deletions

View file

@ -0,0 +1,8 @@
%% This record is used by both epp_tcp_worker and epp_tls_worker.
-record(epp_request,
{method, % get | post (atom)
url, % "https://example.com/some-url"
body, % "" | {multipart [{{<<"raw_frame">>, "Some body"}}]}
cookies, % "" | {multipart [{{<<"raw_frame">>, "Some body"}}]}
headers % [{"User-Agent", <<"EPP proxy">>}, {"Other", <<"Header">>}]
}).

View file

@ -3,12 +3,13 @@
-behaviour(gen_server).
-define(SERVER, ?MODULE).
-include("epp_proxy.hrl").
%% gen_server callbacks
-export([init/1, handle_cast/2, handle_call/3, start_link/1]).
-export([code_change/3]).
-record(state,{socket, length, session_id}).
-record(request,{method, url, body, cookies, headers}).
init(Socket) ->
logger:info("Created a worker process"),
@ -25,9 +26,9 @@ handle_cast(greeting, State = #state{socket=Socket, session_id=SessionId}) ->
logger:info("Request: ~p~n", [Request]),
{_Status, _StatusCode, _Headers, ClientRef} =
hackney:request(Request#request.method, Request#request.url,
Request#request.headers, Request#request.body,
[{cookie, Request#request.cookies}, insecure]),
hackney:request(Request#epp_request.method, Request#epp_request.url,
Request#epp_request.headers, Request#epp_request.body,
[{cookie, Request#epp_request.cookies}, insecure]),
{ok, Body} = hackney:body(ClientRef),
@ -58,9 +59,9 @@ handle_cast(process_command, State = #state{socket=Socket, session_id=SessionId}
logger:info("Request: ~p~n", [Request]),
{_Status, _StatusCode, _Headers, ClientRef} =
hackney:request(Request#request.method, Request#request.url,
Request#request.headers, Request#request.body,
[{cookie, Request#request.cookies}, insecure]),
hackney:request(Request#epp_request.method, Request#epp_request.url,
Request#epp_request.headers, Request#epp_request.body,
[{cookie, Request#epp_request.cookies}, insecure]),
{ok, Body} = hackney:body(ClientRef),
@ -115,8 +116,8 @@ request(Command, SessionId, RawFrame) ->
_ ->
Body = {multipart, [{<<"raw_frame">>, RawFrame}]}
end,
Headers = [],
#request{url=URL, method=RequestMethod, body=Body, cookies=[Cookie],
Headers = [{"User-Agent", <<"EPP proxy">>}],
#epp_request{url=URL, method=RequestMethod, body=Body, cookies=[Cookie],
headers=Headers}.
%% Wrap a message in EPP frame, and then send it to socket.

View file

@ -3,6 +3,8 @@
-behaviour(gen_server).
-define(SERVER, ?MODULE).
-include("epp_proxy.hrl").
%% gen_server callbacks
-export([init/1, handle_cast/2, handle_call/3, start_link/1]).
-export([code_change/3]).
@ -10,7 +12,6 @@
-export([request/5]).
-record(state,{socket, length, session_id, common_name, client_cert}).
-record(request,{method, url, body, cookies, headers}).
init(Socket) ->
logger:info("Created a worker process"),
@ -36,9 +37,9 @@ handle_cast(greeting, State = #state{socket=Socket, common_name=SSL_CLIENT_S_DN_
logger:info("Request: ~p~n", [Request]),
{_Status, _StatusCode, _Headers, ClientRef} =
hackney:request(Request#request.method, Request#request.url,
Request#request.headers, Request#request.body,
[{cookie, Request#request.cookies}, insecure]),
hackney:request(Request#epp_request.method, Request#epp_request.url,
Request#epp_request.headers, Request#epp_request.body,
[{cookie, Request#epp_request.cookies}, insecure]),
{ok, Body} = hackney:body(ClientRef),
@ -72,9 +73,9 @@ handle_cast(process_command, State = #state{socket=Socket,
logger:info("Request: ~p~n", [Request]),
{_Status, _StatusCode, _Headers, ClientRef} =
hackney:request(Request#request.method, Request#request.url,
Request#request.headers, Request#request.body,
[{cookie, Request#request.cookies}, insecure]),
hackney:request(Request#epp_request.method, Request#epp_request.url,
Request#epp_request.headers, Request#epp_request.body,
[{cookie, Request#epp_request.cookies}, insecure]),
{ok, Body} = hackney:body(ClientRef),
@ -129,8 +130,9 @@ request(Command, SessionId, RawFrame, CommonName, ClientCert) ->
Body = {multipart, [{<<"raw_frame">>, RawFrame}]}
end,
Headers = [{"SSL_CLIENT_CERT", ClientCert},
{"SSL_CLIENT_S_DN_CN", CommonName}],
#request{url=URL, method=RequestMethod, body=Body, cookies=[Cookie],
{"SSL_CLIENT_S_DN_CN", CommonName},
{"User-Agent", <<"EPP proxy">>}],
#epp_request{url=URL, method=RequestMethod, body=Body, cookies=[Cookie],
headers=Headers}.
%% Wrap a message in EPP frame, and then send it to socket.