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

[rust] Support for web proxy in Selenium Manager #11575

Merged
merged 9 commits into from
Jan 30, 2023
Merged

Conversation

bonigarcia
Copy link
Member

@bonigarcia bonigarcia commented Jan 20, 2023

Description

This PR implements a couple of new flags for Selenium Manager:

  • --proxy <PROXY>: HTTP(S) proxy for network connection (e.g., https://myproxy.net:8080)
  • --timeout <TIMEOUT>: Timeout for network requests (in seconds). This timeout is applied from when the request starts connecting until the response body has finished [default: 120 seconds]

Motivation and Context

This PR is part of the development of Selenium Manager M3 (requested in #11294).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Sorry, something went wrong.

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

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

Not sure if this has been discussed elsewhere, but if a user is behind a proxy, do we need to invoke Selenium Manager in the bindings with the --proxy and --timeout flags? (Seems there is a default value for timeout, so the flag might not be needed).

If the bindings do need to invoke Selenium Manager with those flags, how will the bindings know if there is a proxy set? Should they detect it? Wouldn't it be easier if Selenium Manager detects that it is being a proxy so we do not write the same code across bindings?

@bonigarcia
Copy link
Member Author

The --timeout flag is not required for the proxy setup. I included it in this PR since I realized that this option deserves to be configurable during the implementation of this PR (e.g., for one of the implemented tests). But it could also be a separate PR.

Regarding proxy, as I imagine it (or, for example, in the way in which the proxy setup works in WebDrivermanager), the user is the one who configures the proxy URL. I don't know how to make this discovery automatic. But there are some cases where that is not possible, for the best of my knowledge, for example, for authenticated web proxies (e.g., http://user:pass@my-proxy.net).

Therefore, IMO the bindings should provide a way to configure the proxy URL, and when that info is specified by the user, the bindings invoke Selenium Manager using --proxy <url>.

@diemol
Copy link
Member

diemol commented Jan 23, 2023

Right, authenticated proxies are tricky. I am not sure how we can set an authenticated proxy in the bindings these days. Probably we need to review that, and if a proxy is set, then pass it along?

@bonigarcia
Copy link
Member Author

I think that having the flag --proxy in Selenium Manager can be helpful in some cases. In addition, if an automatic proxy setup can be done (in the Rust side), it will help for sure. I don't know if it is possible in Rust, I am starting to search now.

@diemol
Copy link
Member

diemol commented Jan 24, 2023

Yes, we should have the flag to set the proxy, I was just thinking if there is a way to centralize most of the code in Selenium Manager. Bindings have a way to set a proxy for the browser, not the HTTP connection, which is why I wonder how each binding is doing that bit. @titusfortner, do you know?

@titusfortner
Copy link
Member

I think we can/(need to?) use the same info that gets passed in to the driver with the Options instance, and we're already going to be parsing Options instance.

@bonigarcia
Copy link
Member Author

bonigarcia commented Jan 24, 2023

Yes, I think the optimal choice is to reuse the proxy specified by the user as options (i.e., http://proxy:port or https://proxy:port) to invoke Selenium Manager with the --proxy URL from the bindings.

For instance, in the Java bindings, when the user does the following:

        Proxy proxy = new Proxy();
        proxy.setHttpProxy("proxy:port");

        ChromeOptions options = new ChromeOptions();
        options.setProxy(proxy)

... internally, the Java bindings invoke Selenium Manager with --proxy http://proxy:port.

And when the proxy is secure:

        Proxy proxy = new Proxy();
        proxy.setSslProxy("proxy:port");

        ChromeOptions options = new ChromeOptions();
        options.setProxy(proxy)

... the call to Selenium Manager should be --proxy https://proxy:port. Is that right?

@titusfortner
Copy link
Member

This generally seems correct. I'm guessing we prefer ssl over http.

Actually, I'm not a proxy person. Would http even work for downloading drivers since everything redirects to https these days?

@bonigarcia bonigarcia requested a review from diemol January 29, 2023 17:13
Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

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

Thank you, @bonigarcia!

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.

None yet

3 participants