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

Fix for #2989 - Cryptomator using the configured proxy #2993

Conversation

odouglsantos
Copy link

@odouglsantos odouglsantos commented Jul 8, 2023

Given issue closes #2989 Cryptomator is not using system proxy to connect to Cryptomator update checker or hub.

During the debug I noticed that it was missing to inject the ProxySelector.getDefault() that returns the default proxy of the system. I performed the configurant tests via JVM Args and the JAVA_TOOL_OPTIONS environment variable both using the parameters -Djava.net.useSystemProxies=true -Dhttp.proxyHost=186.248.206.147 -Dhttp.proxyPort=8080.

Remembering that without the definition of these attributes, the check update works normally

Unfortunately I was only able to test it on MacOS.

@CLAassistant
Copy link

CLAassistant commented Jul 8, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@overheadhunter overheadhunter left a comment

Choose a reason for hiding this comment

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

I assumed the system proxy was used anyway. You live and learn.

We do use the java.net.http.HttpClient in various other places as well. So I think we should add the ProxySelector in each of these places.

- better use of the Optional class
- throws IllegalArgumentException is more appropriate when a required object is not present
@odouglsantos
Copy link
Author

I assumed the system proxy was used anyway. You live and learn.

We do use the java.net.http.HttpClient in various other places as well. So I think we should add the ProxySelector in each of these places.

Hello,

I uploaded the updates including ProxySelector in all HttpClient builders and I took the liberty of adding in this PR also small improvements in some code snippets that use Optional and replacing the exception NullPointerException to IllegalArgumentException, therefore, it is the best approach for a must-have item.

Copy link
Member

@overheadhunter overheadhunter 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, lgtm!

However I wonder why the provideHttpClient() returns an Optional in the first place... 😅

Copy link
Member

@infeo infeo left a comment

Choose a reason for hiding this comment

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

I already wondered, that this PR changes something, because in testing with a colleague only using the proxy selector the update checker still used the "normal" internet connection.

Not specifying the proxy let's automatically use the default proxy, see also the JDK implementation of the HttpClientImpl:

private HttpClientImpl(HttpClientBuilderImpl builder, SingleFacadeFactory facadeFactory) {
    /* ... some code */
    this.userProxySelector = builder.proxy;
    this.proxySelector = Optional.ofNullable(userProxySelector)
            .orElseGet(HttpClientImpl::getDefaultProxySelector);
    /*...*/
}

What's doing the trick is using the property java.net.useSystemProxies=true. And this property needs to be set in our build scripts.

@infeo infeo closed this Jul 13, 2023
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.

Cryptomator does not use the configured system proxy
4 participants