0

The proxy originally is not set and shown as undefined:

httpc:get_options(all).
{ok,[{proxy,{undefined,[]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}

I'm able to set the proxy option without problem:

httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},["localhost"]}}]).

How do you unset the proxy back not undefined (or no proxy) when it is not needed? I tried:

httpc:set_options([{proxy,{undefined, []}}]).
But it throws an exception:
** exception throw: {error,{bad_option,proxy,{undefined,[]}}}
     in function  httpc:bad_option/2 (httpc.erl, line 1102)
     in call from httpc:validate_options/2 (httpc.erl, line 932)
     in call from httpc:validate_options/1 (httpc.erl, line 922)
     in call from httpc:set_options/2 (httpc.erl, line 236)

What am I doing wrong?

casillic
  • 1,837
  • 1
  • 24
  • 29
  • Well I guess I could always just use: exit(whereis(httpc_manager), kill). And let the supervisor make a fresh one. But was hoping for way to clear the proxy information out without having to resort to killing it. – casillic Mar 06 '19 at 17:03

1 Answers1

2

What you are doing wrong that is argument format you pass to the function. Right format is

httpc:set_options([{proxy, {{"", 0},[]}}]).

Now proxy host will be "":0. But I do not know is it acceptable for your task.

Response to comment: Try to set 'proxy' option directly to http_manager instead of kill him:

httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).

Look at erlang shell:

1> inets:start().
ok
2> httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},["localhost"]}}]).
ok
3> httpc:get_options(all).
{ok,[{proxy,{{"www-proxy.mycompany.com",8000},
             ["localhost"]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}
4> httpc_manager:set_options([{proxy,{undefined, []}}],httpc_manager).
ok
5> httpc:get_options(all).                                            
{ok,[{proxy,{undefined,[]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}
Alexei K
  • 142
  • 1
  • 5
  • Yes, looking at the code, they are looking for {{::list(), ::non_neg_integer()}, ::list()} like you indicate. But not sure this suggestion works. Is it equivalent as having no proxy set? It may try to route to no where. I will try it and we will see what happens. Will report back soon. – casillic Mar 06 '19 at 23:57
  • That did not work. The only work around I've found is to kill the httpc manager with exit(whereis(httpc_manager),kill) when I need proxy reset. Which starts over with the undefined proxy settings. – casillic Mar 07 '19 at 15:39
  • I add to my answer other solution. Does it work now? – Alexei K Mar 08 '19 at 21:32
  • Yes, that worked! I also had to add the reset for https_proxy. e.g. httpc_manager:set_options([{https_proxy,{undefined, []}}],httpc_manager). – casillic Mar 09 '19 at 01:38