Skip to content

Commit 236a0ed

Browse files
author
Maciej Szlosarczyk
authored
Merge pull request #19 from internetee/move-records-to-header
Move records to header
2 parents ae478d6 + a23e2ab commit 236a0ed

8 files changed

Lines changed: 31 additions & 21 deletions

File tree

apps/epp_proxy/include/epp_proxy.hrl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
epp_verb % Epp verb that is targeted, plus 'error'
99
}).
1010

11-
-type epp_request() :: #epp_request{}.
11+
-record(valid_frame, {command, cl_trid, raw_frame}).
12+
13+
-record(invalid_frame, {code, cl_trid, message}).
1214

15+
-record(state, {socket, session_id, headers}).
16+
17+
-type epp_request() :: #epp_request{}.
1318

1419
-define(XMLErrorCode, <<"2001">>).
1520

apps/epp_proxy/priv/test_backend_app/epp_server.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class EppServer < Roda
88

99
r.on "session" do
1010
r.get "hello" do
11-
render("session/hello")
11+
if r.cookies['session']
12+
render("session/hello")
13+
end
1214
end
1315

1416
r.post "login" do

apps/epp_proxy/src/epp_http_client.erl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212

1313
%% Callback API
1414
request(#epp_request{} = Request) ->
15-
HackneyArgs = handle_args(Request),
16-
case apply(hackney, request, HackneyArgs) of
15+
[Method, URL, Headers, Payload, Options] =
16+
handle_args(Request),
17+
case hackney:request(Method, URL, Headers, Payload,
18+
Options)
19+
of
1720
{error, Error} -> log_and_return_canned(Error, Request);
1821
{Status, _StatusCode, _Headers, ClientRef} ->
1922
{ok, Body} = hackney:body(ClientRef), {Status, Body}
@@ -28,7 +31,7 @@ request_builder(Map) -> request_from_map(Map).
2831
handle_args(#epp_request{method = get, url = URL,
2932
headers = Headers, cookies = Cookies,
3033
epp_verb = ?helloCommand}) ->
31-
[get, URL, Headers, "", [{cookie, Cookies}, insecure]];
34+
[get, URL, Headers, "", hackney_options(Cookies)];
3235
%% For error command, we convert the message and code into query parameters,
3336
%% and append them to the original URL.
3437
handle_args(#epp_request{method = get, url = URL,
@@ -37,13 +40,12 @@ handle_args(#epp_request{method = get, url = URL,
3740
QueryString = hackney_url:qs(Payload),
3841
CompleteURL = [URL, <<"?">>, QueryString],
3942
[get, CompleteURL, Headers, "",
40-
[{cookie, Cookies}, insecure]];
43+
hackney_options(Cookies)];
4144
%% For valid commands, we set the multipart body earlier, now we just pass it on.
4245
handle_args(#epp_request{method = post, url = URL,
4346
payload = Payload, headers = Headers,
4447
cookies = Cookies}) ->
45-
[post, URL, Headers, Payload,
46-
[{cookie, Cookies}, insecure]].
48+
[post, URL, Headers, Payload, hackney_options(Cookies)].
4749

4850
%% Map request and return values.
4951
request_from_map(#{command := ?errorCommand,
@@ -79,6 +81,13 @@ request_from_map(#{command := Command,
7981
lager:info("Request from map: [~p]~n", [Request]),
8082
Request.
8183

84+
%% Get hackney options
85+
hackney_options(Cookies) ->
86+
case application:get_env(epp_proxy, insecure) of
87+
false -> [{cookie, Cookies}, insecure];
88+
_ -> [{cookie, Cookies}]
89+
end.
90+
8291
%% Return form data or an empty list.
8392
request_body(?helloCommand, _, _) -> "";
8493
request_body(_Command, RawFrame, nomatch) ->

apps/epp_proxy/src/epp_tcp_worker.erl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212

1313
-export([code_change/3]).
1414

15-
-record(valid_frame, {command, cl_trid, raw_frame}).
16-
17-
-record(invalid_frame, {code, cl_trid, message}).
18-
19-
-record(state, {socket, session_id, headers}).
20-
2115
%% Initialize process
2216
%% Assign an unique session id that will be passed on to http server as a cookie
2317
init(Socket) ->

apps/epp_proxy/src/epp_tls_worker.erl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212

1313
-export([code_change/3]).
1414

15-
-record(valid_frame, {command, cl_trid, raw_frame}).
16-
17-
-record(invalid_frame, {code, cl_trid, message}).
18-
19-
-record(state, {socket, session_id, headers}).
20-
2115
%% Initialize process
2216
%% Assign an unique session id that will be passed on to http server as a cookie
2317
init(Socket) ->
@@ -171,7 +165,8 @@ log_on_invalid_handshake(Ip, Error) ->
171165

172166
log_opened_connection(Ip) ->
173167
ReadableIp = epp_util:readable_ip(Ip),
174-
lager:info("New client connection. IP: ~s, Process: ~p.~n",
168+
lager:info("New client connection. IP: ~s, Process: "
169+
"~p.~n",
175170
[ReadableIp, self()]).
176171

177172
%% Extract state info from socket. Fail if you must.

config/docker.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{dev_mode, true},
44
{tcp_port, 3333},
55
{tls_port, 700},
6+
{insecure, false},
67
{epp_session_url, "http://epp:3000/epp/session/"},
78
{epp_command_url, "http://epp:3000/epp/command/"},
89
{epp_error_url, "http://epp:3000/epp/error/"},

config/sys.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
%% TLS port, specified in RFC to 700, but can be set to anything else
88
%% in case that is needed.
99
{tls_port, 700},
10+
%% When set to true, you can connect to EPP over HTTPS endpoints without
11+
%% verifying their TLS certificates.
12+
{insecure, false}
1013
%% URL of EPP endpoints. Can be pointed at a web server (Apache/NGINX)
1114
%% Can contain port (https://some-host:3000/epp/session)
1215
%% Honors the prepended protocol (http / https).

config/test.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{epp_proxy, [{dev_mode, true},
33
{tcp_port, 1180},
44
{tls_port, 1443},
5+
{insecure, false},
56

67
{epp_session_url, "http://localhost:9292/session/"},
78
{epp_command_url, "http://localhost:9292/command/"},

0 commit comments

Comments
 (0)