kesc

kesc

How to configure inets (httpc) default profile at startup to connect via a proxy?

Has anyone configured inets default profile (to use a proxy) on startup?

I am using the new relic elixir agent dependency and :inets is started by that (as part of extra applications in that project). My primary aim is to have the :httpc client used by the new relic agent, connect via a proxy (that exists in my company’s production environment) when connecting to the new relic servers.

I tried following the example in the inets user guide which said to add this to the configuration: [{inets, [{services, [{httpc, PropertyList}]}]}] I translated that to

config :inets, services: [ httpc: [ proxy: {{'http://proxy.com', 1234}, []} ] ]

But that doesnt work.

iex>:httpc.get_options(:all) 
{:ok, [ proxy: {:undefined, []}, https_proxy: {:undefined, []}, pipeline_timeout: 0, max_pipeline_length: 2,...

Please do correct me if I’m approaching this the wrong way, folks.

Most Liked

kip

kip

ex_cldr Core Team

I think you should be able to put it in your application.ex file. Something like the foilowing (which is just editing the generated application.ex for an application called ppp):

  def start(_type, _args) do
    children = [
      # Start the Telemetry supervisor
      PppWeb.Telemetry,
      # Start the Ecto repository
      Ppp.Repo,
      # Start the PubSub system
      {Phoenix.PubSub, name: Ppp.PubSub},
      # Start Finch
      {Finch, name: Ppp.Finch},
      # Start the Endpoint (http/https)
      PppWeb.Endpoint
      # Start a worker by calling: Ppp.Worker.start_link(arg)
      # {Ppp.Worker, arg}
    ]

    # Add these lines
    Application.start(:inets)
    :ok = :httpc.set_options([{:proxy, {{'http://proxy.com', 1234},[]}}])

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: Ppp.Supervisor]
    Supervisor.start_link(children, opts)
  end

I’m sure this is not the most sophisticated solution but it might be a path forward.

kip

kip

ex_cldr Core Team

A couple of thoughts (not tested):

  1. You can tell OTP not to start new_relic_agent automatically by configuring runtime: false. For example:
defp deps do
  [
    {:new_relic_agent, "~> 1.0", runtime: false}
  ]
end

Then you can start it up whenever you want. For example, using my previous code:

Application.start(:inets)
:ok = :httpc.set_options([{:proxy, {{'http://proxy.com', 1234},[]}}])
Application.start(:new_relic_agent)

I also see that you can configure :httpc_request_options so its possible that you could simply do the following (untested): Seems :proxy is not a valid http_option.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement