Morzaram

Morzaram

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)

Showing Posts 1 to 4

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.

Morzaram

Morzaram OP

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!

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!()
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: %{}
}
— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews