Skip to content

Instantly share code, notes, and snippets.

@ohnit
Created March 30, 2023 16:34
Show Gist options
  • Save ohnit/2349462502cdb09e6d569e1957cbfdd7 to your computer and use it in GitHub Desktop.
Save ohnit/2349462502cdb09e6d569e1957cbfdd7 to your computer and use it in GitHub Desktop.
Using a Debugging Proxy with Elixir

Using a Debugging Proxy with Elixir

You can use a debugging proxy (such as ProxyMan or Charles Proxy) to see outgoing calls coming from your Elixir project. Unfortunately, Elixir doesn't look at your system's proxy settings, so you have to set the proxying manually in your networking library. Here I am using Tesla with Hackney.

use Tesla

adapter(Tesla.Adapter.Hackney, proxy: {"localhost", 9090}, ssl_options: [{:verify, :verify_none}])

# plug Tesla.Middleware.Compression
  • The default port for ProxyMan is 9090, the default for Charles Proxy is 8888.
  • localhost can also be the 127.0.0.1. This will code only proxy the calls in the module it is added to. I found in the past that adding this to multiple module somehow confused the networking library (I think base urls got swapped). To get around this problem, I give each module a different alias for localhost, like I added localhost-1 to my local routing which still points to 127.0.0.1.
  • never commit verify_none. It turns off ssl certificate validation. Without this you would need to specify ProxyMan's ssl cert info in order to decrypt https requests (which was a bit confusing for me).
  • disabling Tesla.Middleware.Compression was necessary. I think it's because ProxyMan already unzipped the response, but left the header specifying compression, which confused Tesla. Alternatively, use the debugging proxy to remove this header.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment