Class ProxyUtil

java.lang.Object
org.omegazero.proxy.util.ProxyUtil

public class ProxyUtil extends Object
  • Field Details

    • clientImplNamespace

      public static final String clientImplNamespace
      The namespace of default client manager IDs to use.
      Since:
      3.10.1
    • serverImplNamespace

      public static final String serverImplNamespace
      The namespace of server implementation names to use.
      Since:
      3.10.1
  • Constructor Details

    • ProxyUtil

      public ProxyUtil()
  • Method Details

    • hostMatches

      public static boolean hostMatches(String expr, String hostname)
      Checks if the given hostname matches the expression (expr) containing the wildcard character '*'. The wildcard character matches any character, including '.' (dot). If no wildcard character is used in expr, this function behaves exactly the same as String.equals(Object).

      Examples:

      expr hostname Return value
      *.example.com foo.example.com true
      *.example.com foo.example.org false
      subdomain.*.net subdomain.example.net true
      *subdomain.*.net othersubdomain.example.net true
      Parameters:
      expr -
      hostname -
      Returns:
      true if the given hostname matches the expression
      Implementation Note:
      This function currently cannot handle certain edge cases, for example: expr = a.n*n.a and hostname = a.nnnn.a returns false, even though it should return true. Given that such a hostname expression is quite unlikely to be used in actual configurations, this is fine for now.
    • handleBackpressure

      public static void handleBackpressure(org.omegazero.net.socket.SocketConnection writeStream, org.omegazero.net.socket.SocketConnection readStream)
      Checks if the writeStream (the connection where data is being written to) is connected (or about to be) and is buffering write calls (SocketConnection.isWritable() returns false). If that is the case, reads from the readStream will be blocked using SocketConnection.setReadBlock(boolean) until the writeStream is writable again.

      This method uses the onWrite callback of the SocketConnection, which should not be used when this function is in use.

      Parameters:
      writeStream - The connection where data is being written to
      readStream - The connection where reads should be blocked until writeStream is writable again
      Throws:
      ClassCastException - If writeStream is not a AbstractSocketConnection
    • connectUpstreamTCP

      @Deprecated public static org.omegazero.net.socket.SocketConnection connectUpstreamTCP(Proxy proxy, boolean downstreamSecurity, UpstreamServer userver, String... alpn) throws IOException
      Deprecated.
      Connects to an upstream server over TCP, plaintext or encrypted using TLS.
      Parameters:
      proxy - The proxy instance to connect with
      downstreamSecurity - Whether the client connection was encrypted
      userver - The upstream server to connect to
      alpn - The protocols to advertise using TLS ALPN
      Returns:
      The new connection
      Throws:
      IOException - If an IO error occurred
      Since:
      3.3.1
    • connectUpstreamTCP

      public static org.omegazero.net.socket.SocketConnection connectUpstreamTCP(Proxy proxy, org.omegazero.net.socket.SocketConnection downstreamConnection, boolean downstreamSecurity, UpstreamServer userver, String... alpn) throws IOException
      Connects to an upstream server over TCP, plaintext or encrypted using TLS, depending on the context and server settings.
      Parameters:
      proxy - The proxy instance to connect with
      downstreamConnection - The client connection
      downstreamSecurity - Whether the client connection was encrypted
      userver - The upstream server to connect to
      alpn - The protocols to advertise using TLS ALPN
      Returns:
      The new connection
      Throws:
      IOException - If an IO error occurred
      Since:
      3.7.1
      See Also: