Class CopilotProxyConfig
Proxy settings are resolved through Vaadin Flow's ProxyFactory, which
reads (in order) system properties, the user and project .npmrc files
and environment variables (HTTP_PROXY / HTTPS_PROXY /
NOPROXY). Non-proxy host rules are honored, and proxies requiring
authentication (username/password) are supported.
-
Method Summary
Modifier and TypeMethodDescriptionstatic reactor.netty.http.client.HttpClientApplies the resolved proxy (including authentication and non-proxy hosts) to a Reactor NettyHttpClientfor requests targeting the given URL.static StringReturns a human-readable explanation when the given error was caused by a failed proxy authentication, ornullif it was not.static StringdescribeProxyForLog(com.vaadin.flow.server.frontend.installer.ProxyConfig.Proxy proxy) Returns a credential-free description of the given proxy (host:port, or"none"when there is no proxy), suitable for logging.static com.vaadin.flow.server.frontend.installer.ProxyConfig.ProxygetProxyForUrl(String url) Resolves the proxy that should be used for the given URL, honoring non-proxy host rules.static HttpClient.BuilderCreates aHttpClient.Builderwith the resolved proxy (including authentication) applied for requests targeting the given URL.static voidprepareProxyAuthentication(File projectDirectory) Enables tunneled Basic proxy authentication when a proxy that would apply to the Copilot server requires it.
-
Method Details
-
getProxyForUrl
public static com.vaadin.flow.server.frontend.installer.ProxyConfig.Proxy getProxyForUrl(String url) Resolves the proxy that should be used for the given URL, honoring non-proxy host rules.- Parameters:
url- the target URL- Returns:
- the proxy to use, or
nullif no proxy applies
-
describeProxyAuthenticationFailure
Returns a human-readable explanation when the given error was caused by a failed proxy authentication, ornullif it was not. The JDK reports"too many authentication attempts"when the proxy keeps rejecting the configured credentials.- Parameters:
error- the error thrown by an HTTP request- Returns:
- a message describing the proxy authentication failure, or
nullif the error is unrelated
-
describeProxyForLog
public static String describeProxyForLog(com.vaadin.flow.server.frontend.installer.ProxyConfig.Proxy proxy) Returns a credential-free description of the given proxy (host:port, or"none"when there is no proxy), suitable for logging. Deliberately avoidsProxyConfig.Proxy.toString()so the guarantee that proxy credentials are never logged does not depend on that method's implementation.- Parameters:
proxy- the proxy, ornull- Returns:
- a description safe to log
-
prepareProxyAuthentication
Enables tunneled Basic proxy authentication when a proxy that would apply to the Copilot server requires it.This must run before the first
java.net.httpclient is created anywhere in the JVM: the JDK readsjdk.http.auth.tunneling.disabledSchemesinto a constant on first use and disables Basic on HTTPSCONNECTtunnels by default, so enabling it afterwards has no effect and an authenticated proxy rejects the tunnel with a 407. Copilot's earliestjava.net.httpclient is the IDE plugin's, so this is invoked from there.The project directory is passed in rather than obtained from
ProjectFileManager: at this point project detection has not run, and triggering it would recurse back into IDE-plugin creation. Proxy settings from system properties, the user.npmrcand environment variables are read regardless.Best-effort: any failure to resolve the proxy is swallowed so client creation is never blocked.
- Parameters:
projectDirectory- directory used to locate a project-level.npmrc, ornullto skip that source
-
newHttpClientBuilder
Creates aHttpClient.Builderwith the resolved proxy (including authentication) applied for requests targeting the given URL. When no proxy is configured, the JVM defaultProxySelectoris used so that standard proxy system properties are still honored.The builder is created here, rather than accepting one, so that tunneled Basic authentication can be enabled before the
java.net.httpimplementation classes load. The JDK readsjdk.http.auth.tunneling.disabledSchemesinto a constant on first use, so setting it afterHttpClient.newBuilder()would be too late and the proxy would reject theCONNECTwith a 407.- Parameters:
url- the target URL- Returns:
- a new builder with the proxy applied
-
configure
public static reactor.netty.http.client.HttpClient configure(reactor.netty.http.client.HttpClient client, String url) Applies the resolved proxy (including authentication and non-proxy hosts) to a Reactor NettyHttpClientfor requests targeting the given URL. When no proxy is configured, proxy system properties are honored viaClientTransport.proxyWithSystemProperties().- Parameters:
client- the Reactor Netty client to configureurl- the target URL- Returns:
- the configured client
-