-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(proxy): client proxy for http and https #639
Conversation
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
Good morning Hyper community, I've rebased my client proxy changes on master and made all the tests pass. I need to write some tests but I would like to get some advice first on the architecture. I tried a couple of alternatives like removing the concept of the Route or not have it closely tied to the HttpStream. The challenge is that the proxying is a pretty low level concept so any change tends to propagate through the codebase. Where would you like me to take next? We have a stable commit right now and we can compare with other approaches. |
At the moment there is an assumption that both HTTP and HTTPS will be handled by the same proxy. This could cause problems. While I do not need it I know others do require authentication support. As for design concerns, is there a reason you made a new constructor instead of allowing the user to call something like
Except as I noted above this only works when one proxy config works for both settings. If there is a separate HTTP and HTTPS proxy things get more complex. This complexity needs to be duplicated in each and every client project using hyper. Not directly this patch's problem but reading env::var("http_proxy") is not trivial. I need to use something like |
The code works as expected for HTTP requests with the caveat that all requests go to the proxy because there is no support for Any attempt to access a SSL url generates a SIGPIPE for me. |
@shaleh thanks for the feedback. I will add authentication and fix the https crash. I also need to add tests, I will do that after I refactor the internals based on other feedback. I do not know how frequent it is for people to have multiple proxies. If we assume that most people have one proxy for all requests then the current API is the simplest. For your use case you can create 3 Hyper clients in the three configurations that you describe:
This keeps the library simple and allows flexibility in the consuming application, with the downside that there is more code in the application. Let me know what you think. |
The point of a library is to make the application author's life easier AND to have one place to put redundant code. Almost every user of the hyper crate will need to implement proxy support at some point. The crate should make it easy for the application author to get it right. Ideally this means stuffing as much proxy knowledge into the crate as possible. I'd like to see a baked in way to create a hyper based Client that read its settings from the environment. A similar bit of code that took a list of proxies instead of reading the environment would be another useful interface for those that want the proxy to come from their own configs. Sorry, I would have written code instead of asking but I have been busy on other projects. |
Got it, I have been working on multiple proxies but I have only 6-8 On Fri, Oct 16, 2015 at 1:25 PM, Sean Perry [email protected]
|
I think the task of getting the proxy settings should be outside of hyper. The configuration could come from anywhere (environment variables, command line arguments, config files, hard coded, etc). Instead, hyper should accept the parameters in the Proxy constructor. For instance: client.set_proxy(Proxy::Http {
host: env::var("HTTP_PROXY_HOST").unwrap(),
port: env::var("HTTP_PROXY_PORT").unwrap(),
}) Also, it is possible to build a Proxy entirely outside of this crate, and use a hyper Client internally. That's why I've mentioned trying not to adjust too much of the internal http protocol modules. The Client (and Request) just need to be able to use all the parts of RFC7230, such as the CONNECT method and alternate RequestUri formats. I'd rather if the logic to use those was contained in the |
Yeah, I have been trying to be less invasive. I think that some internal On Sat, Oct 17, 2015 at 10:59 AM, Sean McArthur [email protected]
|
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
@seanmonstar I got rid of the Route and instead added a request_uri in Request (and RequestHead) as you had suggested on the initial PR. I've added a list of proxies each with their own proxy policies. All of this is only in place for the Http 1.1 code. For the SSL NetworkConnector there is still one architecture issue because all the SSL types are defined only in the h2.rs file. So the NetworkConnector's connect still defers back to the Proxy, and this code is not ported to use the new list of proxies as per the desired APIs. Where do you want me to take this code next? |
@@ -107,18 +110,28 @@ impl Client { | |||
Client::with_connector(Pool::new(config)) | |||
} | |||
|
|||
pub fn with_proxy_config(config: proxy::Config) -> Client { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between using a Connector with_proxy, and calling client.add_proxy
?
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
This is Work In Progress.
Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:
Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md This message was auto-generated by https://gitcop.com |
@seanmonstar, thanks for your feedback I've addressed some of it. I love your suggestion to have an implementation of NetworkConnector for Proxy, not yet implemented. What needs to happen is the following:
With the current API this is not possible. This is the reason why the proxy is passed down. Note that the Pool NetworkConnector has a different use case, the lower level NetworkConnectors are allowed to open their own sockets. Please feel free to take over this PR and play with some approaches :) |
As mentioned in the ticket I would love to help drive this PR forward. Proxy support is very important to me. |
Ideally some of this work can be brought over to the async world, as I hope to merge async io soon. It may even be that since the async version of hyper is a little lower level, using a proxy may be easier. |
This is a proof of concept for supporting client side proxies. The tests
are not passing yet, I am just soliciting feedback on the architecture.
The use cases that I see are the following
the proxy
So once a connection to a host is established it will either use the
proxy
all the time or it will be a direct connection all the time. The Pool
keys streams on host-port-scheme so a stream is either proxy or direct.
The logic is the following:
Let me know what you think.