1212
1313% % Callback API
1414request (# 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).
2831handle_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.
3437handle_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.
4245handle_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.
4951request_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.
8392request_body (? helloCommand , _ , _ ) -> " " ;
8493request_body (_Command , RawFrame , nomatch ) ->
0 commit comments