Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP_PROXY doesn't set host for a connection, using proxy as host #446

Open
joshuataylor opened this issue Jul 12, 2024 · 2 comments
Open
Labels

Comments

@joshuataylor
Copy link

joshuataylor commented Jul 12, 2024

Reading:
https://hexdocs.pm/mint/Mint.HTTP.html#connect/4-proxying

A minimal example, using mitmproxy:

proxy_details = {:http, "127.0.0.1", 9055, []}
{:ok, conn} = Mint.HTTP.connect(:http, "example.com", 80, proxy: proxy_details)
{:ok, conn, request_ref} = Mint.HTTP.request(conn, "GET", "/", [], nil)

The raw request seems to be:

GET / HTTP/1.1
host: 127.0.0.1:9055
user-agent: mint/1.5.1

When using hackney, this seems to work:

# Set up the proxy options
proxy_opts = [
  proxy: {"127.0.0.1", 9055}
]

# Make the request using hackney
:hackney.request(:get, "http://example.com", [], "", proxy_opts)

Request:

GET / HTTP/1.1
Host: example.com
User-Agent: hackney/1.20.1

(HTTPoison also works, HTTPoison.get("http://example.com", [], [{:proxy, string_url()}]))

Mint.UnsafeProxy:

conn: %Mint.UnsafeProxy{
  hostname: "example.com",
  port: 80,
  scheme: :http,
  module: Mint.HTTP1,
  proxy_headers: [],
  state: %Mint.HTTP1{
    host: "127.0.0.1",
    port: 9055,
    request: nil,
    streaming_request: nil,
    socket: #Port<0.4>,
    transport: Mint.Core.Transport.TCP,
    mode: :active,
    scheme_as_string: "http",
    requests: {[], []},
    state: :open,
    buffer: "",
    proxy_headers: [],
    private: %{},
    log: false
  }
}
request: %Mint.UnsafeProxy{
  hostname: "example.com",
  port: 80,
  scheme: :http,
  module: Mint.HTTP1,
  proxy_headers: [],
  state: %Mint.HTTP1{
    host: "127.0.0.1",
    port: 9055,
    request: %{
      status: nil,
      version: nil,
      state: :status,
      connection: [],
      body: nil,
      ref: #Reference<0.1840951877.600834051.12099>,
      method: "GET",
      data_buffer: [],
      headers_buffer: [],
      content_length: nil,
      transfer_encoding: []
    },
    streaming_request: nil,
    socket: #Port<0.4>,
    transport: Mint.Core.Transport.TCP,
    mode: :active,
    scheme_as_string: "http",
    requests: {[], []},
    state: :open,
    buffer: "",
    proxy_headers: [],
    private: %{},
    log: false
  }
}
@whatyouhide
Copy link
Contributor

Yeah this seems to be a bug from a super quick look. Wanna give a try to coming up with a patch? 🙃

@joshuataylor
Copy link
Author

I guess calling it "preserve host header"/"keep host header" or something would make sense.

Prior art:
https://docs.mitmproxy.org/stable/concepts-options/#keep_host_header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants