Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit f7e03d0

Browse files
committed
HTTP proxy support
Proxy options can be passed to the trust store to set in the httpc profile. Proxy options are described in: http://erlang.org/doc/man/httpc.html#set_options-2 Example: ``` [{rabbitmq_trust_store, [{proxy_options, [ {proxy, {{"127.0.0.1", 8080},[]}}, {https_proxy, {{"127.0.0.1", 8080},[]}} ] }] }]. ```
1 parent 576d60d commit f7e03d0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/rabbit_trust_store_http_provider.erl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
-behaviour(rabbit_trust_store_certificate_provider).
66

7+
-define(PROFILE, ?MODULE).
8+
79
-export([list_certs/1, list_certs/2, load_cert/3]).
810

911
-record(http_state,{
@@ -13,14 +15,14 @@
1315
}).
1416

1517
list_certs(Config) ->
16-
init(),
18+
init(Config),
1719
State = init_state(Config),
1820
list_certs(Config, State).
1921

2022
list_certs(_, #http_state{url = Url,
2123
http_options = HttpOptions,
2224
headers = Headers} = State) ->
23-
Res = httpc:request(get, {Url, Headers}, HttpOptions, [{body_format, binary}]),
25+
Res = httpc:request(get, {Url, Headers}, HttpOptions, [{body_format, binary}], ?PROFILE),
2426
case Res of
2527
{ok, {{_, 200, _}, RespHeaders, Body}} ->
2628
Certs = decode_cert_list(Body),
@@ -40,7 +42,8 @@ load_cert(_, Attributes, Config) ->
4042
Res = httpc:request(get,
4143
{Url, Headers},
4244
HttpOptions,
43-
[{body_format, binary}, {full_result, false}]),
45+
[{body_format, binary}, {full_result, false}],
46+
?PROFILE),
4447
case Res of
4548
{ok, {200, Body}} ->
4649
[{'Certificate', Cert, not_encrypted}] = public_key:pem_decode(Body),
@@ -54,9 +57,11 @@ join_url(BaseUrl, CertPath) ->
5457
++ "/" ++
5558
string:strip(rabbit_data_coercion:to_list(CertPath), left, $/).
5659

57-
init() ->
58-
inets:start(),
59-
ssl:start().
60+
init(Config) ->
61+
inets:start(httpc, [{profile, ?PROFILE}]),
62+
ssl:start(),
63+
Options = proplists:get_value(proxy_options, Config, []),
64+
httpc:set_options(Options, ?PROFILE).
6065

6166
init_state(Config) ->
6267
Url = proplists:get_value(url, Config),

0 commit comments

Comments
 (0)