mirror of
https://github.com/internetee/epp_proxy.git
synced 2025-08-15 20:13:47 +02:00
Move epp_record into a header file
This commit is contained in:
parent
6ef2b881f8
commit
c74bacfee3
3 changed files with 29 additions and 18 deletions
8
apps/epp_proxy/include/epp_proxy.hrl
Normal file
8
apps/epp_proxy/include/epp_proxy.hrl
Normal 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">>}]
|
||||
}).
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue