Morzaram

Morzaram

Making a Req request with proxy

Hey there,

I’m trying to make a Req request with the following config, but I’m struggling a bit.

The curl I’m trying to make into a Req
curl --proxy my.proxy.com:22225 --proxy-user user:pass -k "myurl.com"

Req.new(
      url: url,
      connect_options: [
        proxy: {
          "http",
          "user:pass@my.proxy.com",
          22225
        }
      ]
    )
    |> Req.get()

When I run this I get:
no case clause matching: {:ok, {"http", "user:pass@my.proxy.com", 22225}}

I’m trying to understand what options to pass through with req, but it doesn’t have any examples for me to reference.

Any help would be appreciated (edited)

Most Liked

Morzaram

Morzaram

Hey thanks so much for responding!

The following code indeed worked.

Req.new(
  url: url,
  connect_options: [
    proxy_headers: [
      {"proxy-authorization", "Basic " <> Base.encode64("user:pass")}
    ],
    proxy: { :http, "my.proxy.com", 22225, [] },
    transport_opts: [ verify: :verify_none ]
  ]
)
|> Req.get()

I’ll make a PR with updated docs. And if I can understand what’s going on with setting http_proxy and https_proxy, I will make a PR for that too when I have a moment. This is a great library! thanks for your efforts on this!

wojtekmach

wojtekmach

Hex Core Team

I haven’t tested but this should work:

Req.get!(
  url,
  connect_options: [proxy: {:http, "localhost", 22225, []}],
  proxy_headers: [{"proxy-authorization", "basic " <> Base.encode64("user:pass")}]
)

There is hardly any documentation for this in Req (Req — req v0.6.2) and very scarce in Mint (Mint.HTTP — Mint v1.9.0) so if you get this to work, a PR with docs improvements would be very appreciated. We have an open issue, Support http_proxy and https_proxy environment variables · Issue #394 · wojtekmach/req · GitHub, to support http_proxy and https_proxy env vars so that would probably be even better way to solve this.

chgeuer

chgeuer

If your proxy has some sort of untrusted X509 cert but you want to use it anyway, you can also use :cacertfile instead of verify: :verify_none:

Req.new(
  url: "https://www.google.com/",
  connect_options: [
    proxy_headers: [
      {"proxy-authorization", "Basic " <> Base.encode64("user:pass")}
    ],
    proxy: { :http, "192.168.1.65", 8888, [] },
    transport_opts: [ 
      # verify: :verify_none,
      cacertfile: "/mnt/c/chgeuer/FiddlerRoot.pem"
    ]
  ]
)
|> Req.get!()

Last Post!

kevinschweikert

kevinschweikert

🥌 CurlReq — CurlReq v0.100.2 can now do this for you!

import CurlReq
~CURL(curl --proxy my.proxy.com:22225 --proxy-user user:pass -k “myurl.com”)

Result:

%Req.Request{
  method: :get,
  url: URI.parse("http://“myurl.com”"),
  headers: %{},
  body: nil,
  options: %{
    connect_options: [
      proxy: {:http, "my.proxy.com", 22225, []},
      proxy_headers: [{"proxy-authorization", "Basic dXNlcjpwYXNz"}],
      transport_opts: [verify: :verify_none]
    ]
  },
  halted: false,
  adapter: &Req.Steps.run_finch/1,
  request_steps: [],
  response_steps: [],
  error_steps: [],
  private: %{}
}

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
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 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

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
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement