Skip to content

Conversation

@Milky2018
Copy link

Add a proxy for http client.

  • The proxy is implemented in proxy.mbt
  • Update README.mbt.md
  • Add a commented test at proxy_test.mbt, it can be verified when developers have a proxy server

@Milky2018 Milky2018 closed this Nov 17, 2025
@Milky2018 Milky2018 deleted the http-proxy branch November 17, 2025 10:42
@Milky2018 Milky2018 restored the http-proxy branch November 17, 2025 10:47
@Milky2018 Milky2018 reopened this Nov 17, 2025
@coveralls
Copy link

coveralls commented Nov 17, 2025

Pull Request Test Coverage Report for Build 796

Details

  • 7 of 33 (21.21%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.1%) to 80.164%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/http/request.mbt 5 7 71.43%
src/http/client.mbt 2 5 40.0%
src/http/proxy.mbt 0 21 0.0%
Totals Coverage Status
Change from base Build 794: -1.1%
Covered Lines: 1370
Relevant Lines: 1709

💛 - Coveralls

// let (response, body) = @http.get("https://www.youtube.com", proxy~)
// inspect(response.code, content="200")
// assert_true(body.text().contains("YouTube"))
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing can be done by:

  • set up a local TCP server
  • use @http.ServerConnection::new to wrap a TCP connection and handle the CONNECT request
  • discard the @http.ServerConnection and inspect the underlying TCP connection for tunneled traffic

ForHttps(String, Int)
ForAll(String, Int)
Custom(http~ : (String, Int), https~ : (String, Int))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this abstraction is necessary. For @http.Client::connect and @http.get, the protocol is always known. So protocol based proxy selection should be done manually by the user IMO, and @http should just accept an optional (host, port) pair for proxy

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think we should leave some room for future HTTPS proxy support (i.e. the CONNECT request itself is TLS encrypted) in the API design

@Guest0x0
Copy link
Collaborator

My idea on API design:

  • add a method @http.Client::connect, which sends a CONNECT request, and turn the @http.Client into a TCP tunnel on success
    • this API could be private at first, but is useful on its own (tunnel non-http traffic through HTTP proxy)
  • make the proxy argument another plain @http.Client. Internally, .connect() will be called on that client

This way we get:

  • HTTPS proxy support for free
  • proxy authentication etc. for free: the user can do whatever @http.Client support on proxy creation, such as passing custom headers

@Guest0x0
Copy link
Collaborator

close via #199

@Guest0x0 Guest0x0 closed this Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants