Package org.omegazero.proxy.util
Class ProxyUtil
java.lang.Object
org.omegazero.proxy.util.ProxyUtil
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.omegazero.net.socket.SocketConnectionconnectUpstreamTCP(Proxy proxy, boolean downstreamSecurity, UpstreamServer userver, String... alpn) Deprecated.static org.omegazero.net.socket.SocketConnectionconnectUpstreamTCP(Proxy proxy, org.omegazero.net.socket.SocketConnection downstreamConnection, boolean downstreamSecurity, UpstreamServer userver, String... alpn) Connects to an upstream server over TCP, plaintext or encrypted using TLS, depending on the context and server settings.static voidhandleBackpressure(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()returnsfalse).static booleanhostMatches(String expr, String hostname) Checks if the given hostname matches the expression (expr) containing the wildcard character '*'.
-
Field Details
-
clientImplNamespace
The namespace of default client manager IDs to use.- Since:
- 3.10.1
-
serverImplNamespace
The namespace of server implementation names to use.- Since:
- 3.10.1
-
-
Constructor Details
-
ProxyUtil
public ProxyUtil()
-
-
Method Details
-
hostMatches
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 asString.equals(Object).Examples:
expr hostname Return value *.example.com foo.example.com true*.example.com foo.example.org falsesubdomain.*.net subdomain.example.net true*subdomain.*.net othersubdomain.example.net true- Parameters:
expr-hostname-- Returns:
trueif the given hostname matches the expression- Implementation Note:
- This function currently cannot handle certain edge cases, for example: expr =
a.n*n.aand hostname =a.nnnn.areturnsfalse, even though it should returntrue. 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()returnsfalse). If that is the case, reads from the readStream will be blocked usingSocketConnection.setReadBlock(boolean)until the writeStream is writable again.This method uses the
onWritecallback of theSocketConnection, which should not be used when this function is in use.- Parameters:
writeStream- The connection where data is being written toreadStream- The connection where reads should be blocked until writeStream is writable again- Throws:
ClassCastException- If writeStream is not aAbstractSocketConnection
-
connectUpstreamTCP
@Deprecated public static org.omegazero.net.socket.SocketConnection connectUpstreamTCP(Proxy proxy, boolean downstreamSecurity, UpstreamServer userver, String... alpn) throws IOException Deprecated.Since 3.7.1, useconnectUpstreamTCP(Proxy, SocketConnection, boolean, UpstreamServer, String...)to pass the client connectionConnects to an upstream server over TCP, plaintext or encrypted using TLS.- Parameters:
proxy- The proxy instance to connect withdownstreamSecurity- Whether the client connection was encrypteduserver- The upstream server to connect toalpn- 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 withdownstreamConnection- The client connectiondownstreamSecurity- Whether the client connection was encrypteduserver- The upstream server to connect toalpn- The protocols to advertise using TLS ALPN- Returns:
- The new connection
- Throws:
IOException- If an IO error occurred- Since:
- 3.7.1
- See Also:
-
connectUpstreamTCP(Proxy, SocketConnection, boolean, UpstreamServer, String...)to pass the client connection