Interface ProxyConfigSelector

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@UnstableApi
@FunctionalInterface
public interface ProxyConfigSelector
Selects the ProxyConfig to use when connecting to a network resource specified by the SessionProtocol and Endpoint parameter. This class may be used to dynamically control what proxy configuration to use for each request.

It should be noted that the only guarantee provided is for a single request, the Endpoint called with select(SessionProtocol, Endpoint) will be equal to the Endpoint called with connectFailed(SessionProtocol, Endpoint, SocketAddress, Throwable).

For instance, the actual SessionProtocol of the connection may differ from the originally requested SessionProtocol depending on the result of protocol negotiation. Similarly, the actual Endpoint of the request may differ from the originally requested Endpoint.

  • Method Details

    • of

      static ProxyConfigSelector of​(ProxySelector proxySelector)
      Provides a way to reuse an existing ProxySelector with some limitations.
      • Incompatibilities when used with JDK's default ProxySelector implementation:
        • Some properties like socksProxyVersion aren't respected
        • This class doesn't attempt to resolve scheme format differences. However, armeria uses some schemes such as "h1c", "h2" which aren't supported by JDK's default ProxySelector. This may be a source of unexpected behavior.
      • Selecting multiple Proxy isn't supported
    • of

      static ProxyConfigSelector of​(ProxyConfig proxyConfig)
      Returns a ProxyConfigSelector which selects a static ProxyConfig for all requests.
    • select

      ProxyConfig select​(SessionProtocol protocol, Endpoint endpoint)
      Selects the ProxyConfig to use when connecting to a network resource specified by the SessionProtocol and Endpoint parameter.
      Parameters:
      protocol - the protocol associated with the endpoint
      endpoint - an endpoint containing the requested host and port
      Returns:
      the selected proxy config which should be non-null
    • connectFailed

      default void connectFailed​(SessionProtocol protocol, Endpoint endpoint, SocketAddress sa, Throwable throwable)
      Called to indicate a connection attempt to the specified SessionProtocol and Endpoint has failed.
      Parameters:
      protocol - the protocol associated with the endpoint
      endpoint - an endpoint containing the requested host and port
      sa - the remote socket address of the proxy server
      throwable - the cause of the failure