Class CopilotProxyConfig

java.lang.Object
com.vaadin.copilot.CopilotProxyConfig

public final class CopilotProxyConfig extends Object
Centralizes resolution of proxy settings and applies them to the various HTTP clients that Copilot uses to reach the Copilot server and other external services.

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 Type
    Method
    Description
    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 Netty HttpClient for requests targeting the given URL.
    static String
    Returns a human-readable explanation when the given error was caused by a failed proxy authentication, or null if it was not.
    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.
    static com.vaadin.flow.server.frontend.installer.ProxyConfig.Proxy
    Resolves the proxy that should be used for the given URL, honoring non-proxy host rules.
    Creates a HttpClient.Builder with the resolved proxy (including authentication) applied for requests targeting the given URL.
    static void
    prepareProxyAuthentication(File projectDirectory)
    Enables tunneled Basic proxy authentication when a proxy that would apply to the Copilot server requires it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 null if no proxy applies
    • describeProxyAuthenticationFailure

      public static String describeProxyAuthenticationFailure(Throwable error)
      Returns a human-readable explanation when the given error was caused by a failed proxy authentication, or null if 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 null if 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 avoids ProxyConfig.Proxy.toString() so the guarantee that proxy credentials are never logged does not depend on that method's implementation.
      Parameters:
      proxy - the proxy, or null
      Returns:
      a description safe to log
    • prepareProxyAuthentication

      public static void prepareProxyAuthentication(File projectDirectory)
      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.http client is created anywhere in the JVM: the JDK reads jdk.http.auth.tunneling.disabledSchemes into a constant on first use and disables Basic on HTTPS CONNECT tunnels by default, so enabling it afterwards has no effect and an authenticated proxy rejects the tunnel with a 407. Copilot's earliest java.net.http client 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 .npmrc and 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, or null to skip that source
    • newHttpClientBuilder

      public static HttpClient.Builder newHttpClientBuilder(String url)
      Creates a HttpClient.Builder with the resolved proxy (including authentication) applied for requests targeting the given URL. When no proxy is configured, the JVM default ProxySelector is 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.http implementation classes load. The JDK reads jdk.http.auth.tunneling.disabledSchemes into a constant on first use, so setting it after HttpClient.newBuilder() would be too late and the proxy would reject the CONNECT with 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 Netty HttpClient for requests targeting the given URL. When no proxy is configured, proxy system properties are honored via ClientTransport.proxyWithSystemProperties().
      Parameters:
      client - the Reactor Netty client to configure
      url - the target URL
      Returns:
      the configured client