类 ProxyConfig

java.lang.Object
io.agentscope.core.model.transport.ProxyConfig

public class ProxyConfig extends Object
Configuration for HTTP and SOCKS proxy.

This class provides a unified configuration for both HTTP and SOCKS proxies, supporting optional authentication and bypass rules.

Usage examples:


 // Simple HTTP proxy
 ProxyConfig proxy = ProxyConfig.http("proxy.example.com", 8080);

 // HTTP proxy with authentication
 ProxyConfig proxy = ProxyConfig.http("proxy.example.com", 8080, "user", "pass");

 // SOCKS5 proxy with authentication
 ProxyConfig proxy = ProxyConfig.socks5("socks.example.com", 1080, "user", "pass");

 // Using builder for advanced configuration
 ProxyConfig proxy = ProxyConfig.builder()
     .type(ProxyType.HTTP)
     .host("proxy.example.com")
     .port(8080)
     .username("user")
     .password("pass")
     .nonProxyHosts(Set.of("localhost", "*.internal.com"))
     .build();
 
  • 方法详细资料

    • http

      public static ProxyConfig http(String host, int port)
      Create a simple HTTP proxy configuration without authentication.
      参数:
      host - proxy server hostname or IP address
      port - proxy server port
      返回:
      a new ProxyConfig instance
    • http

      public static ProxyConfig http(String host, int port, String username, String password)
      Create an HTTP proxy configuration with authentication.
      参数:
      host - proxy server hostname or IP address
      port - proxy server port
      username - authentication username
      password - authentication password
      返回:
      a new ProxyConfig instance
    • socks4

      public static ProxyConfig socks4(String host, int port)
      Create a simple SOCKS4 proxy configuration.

      Note: SOCKS4 does not support authentication.

      参数:
      host - proxy server hostname or IP address
      port - proxy server port
      返回:
      a new ProxyConfig instance
    • socks5

      public static ProxyConfig socks5(String host, int port)
      Create a simple SOCKS5 proxy configuration without authentication.
      参数:
      host - proxy server hostname or IP address
      port - proxy server port
      返回:
      a new ProxyConfig instance
    • socks5

      public static ProxyConfig socks5(String host, int port, String username, String password)
      Create a SOCKS5 proxy configuration with authentication.

      Note: SOCKS5 authentication is only supported when using OkHttp-based transport implementations. JDK HttpClient does not support SOCKS5 authentication.

      参数:
      host - proxy server hostname or IP address
      port - proxy server port
      username - authentication username
      password - authentication password
      返回:
      a new ProxyConfig instance
    • builder

      public static ProxyConfig.Builder builder()
      Create a new builder for ProxyConfig.
      返回:
      a new Builder instance
    • getType

      public ProxyType getType()
      Get the proxy type.
      返回:
      the proxy type
    • getHost

      public String getHost()
      Get the proxy server hostname or IP address.
      返回:
      the proxy host
    • getPort

      public int getPort()
      Get the proxy server port.
      返回:
      the proxy port
    • getUsername

      public String getUsername()
      Get the authentication username.
      返回:
      the username, or null if no authentication is configured
    • getPassword

      public String getPassword()
      Get the authentication password.
      返回:
      the password, or null if no authentication is configured
    • getNonProxyHosts

      public Set<String> getNonProxyHosts()
      Get the set of hosts that should bypass the proxy.

      The set may contain exact hostnames (e.g., "localhost") or wildcard patterns (e.g., "*.internal.com", "192.168.*").

      返回:
      the set of non-proxy hosts, or null if not configured
    • hasAuthentication

      public boolean hasAuthentication()
      Check if authentication credentials are configured.
      返回:
      true if both username and password are set
    • shouldBypass

      public boolean shouldBypass(String hostname)
      Check if the given hostname should bypass the proxy.
      参数:
      hostname - the hostname to check
      返回:
      true if the hostname should bypass the proxy
    • toJavaProxy

      public Proxy toJavaProxy()
      Convert this configuration to a Proxy instance.
      返回:
      the Java Proxy instance
    • getSocketAddress

      public InetSocketAddress getSocketAddress()
      Get the socket address for this proxy.
      返回:
      the proxy socket address
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • equals

      public boolean equals(Object o)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object