Package org.microproxy
Record Class ReverseProxyMode
java.lang.Object
java.lang.Record
org.microproxy.ReverseProxyMode
- Record Components:
scheme-http,httpsortcphost- the upstream host name or IP address (IPv6 without brackets)port- the upstream port
Reverse proxy mode: every request on the listener goes to one fixed upstream server, whatever
its target, as a server of its own rather than a forward proxy. Origin-form requests (
GET
/path) are accepted, and the Host field is set to the upstream's unless HttpProxyServerBootstrap.withKeepHostHeader(boolean) keeps the client's. Filters, scripts, the cache and
logging apply as to any request.
The specification follows mitmproxy's reverse: mode: [scheme://]host[:port]
with an optional trailing slash and no path.
https://host[:port](the default scheme): TLS to the upstream, validated with theMitmManager's server context when one is configured (MitmManager.serverSslContext(String, int, FlowContext)), else the JVM's default trust. HTTP/2 to the upstream when it offers it (HttpProxyServerBootstrap.withHttp2Upstream(boolean), on by default).http://host[:port]: plain HTTP to the upstream.tcp://host:port: each client connection is relayed to the upstream as raw bytes, without parsing.
The listener may itself speak TLS (HttpProxyServerBootstrap.withSslContextSource(org.microproxy.SslContextSource)),
which terminates TLS for the upstream, with HTTP/2 to clients that offer it unless HttpProxyServerBootstrap.withHttp2(boolean) is turned off.
-
Constructor Summary
ConstructorsConstructorDescriptionReverseProxyMode(String scheme, String host, int port) Checks the components. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.host()Returns the value of thehostrecord component.Returns the upstream ashost:port, with IPv6 addresses in brackets.TheHostfield requests get: the host, with the port unless it is the scheme's default, as mitmproxy'surl.hostportwrites it.static ReverseProxyModeParses an upstream server specification,[scheme://]host[:port]: the scheme defaults tohttps, the port to 443 forhttpsand 80 forhttp;tcpneeds a port.static ReverseProxyModeParses a mitmproxy-style mode:reverse:<spec>(seeparse(java.lang.String));regular,transparentandsocks5(seeHttpProxyServerBootstrap.withSocksServer(boolean)), the modes without a fixed upstream, givenull.intport()Returns the value of theportrecord component.booleanrawTcp()Returns whether client connections are relayed as raw bytes (tcp).scheme()Returns the value of theschemerecord component.booleantls()Returns whether the upstream is reached over TLS (https).toString()Returns a string representation of this record class.
-
Constructor Details
-
ReverseProxyMode
Checks the components.- Parameters:
scheme-http,httpsortcphost- the upstream hostport- the upstream port, 1 to 65535- Throws:
IllegalArgumentException- if a component is invalid
-
-
Method Details
-
parse
Parses an upstream server specification,[scheme://]host[:port]: the scheme defaults tohttps, the port to 443 forhttpsand 80 forhttp;tcpneeds a port.- Parameters:
spec- the upstream, such ashttps://example.comorhttp://10.0.0.1:8080- Returns:
- the reverse proxy mode
- Throws:
IllegalArgumentException- if the specification is invalid
-
parseMode
Parses a mitmproxy-style mode:reverse:<spec>(seeparse(java.lang.String));regular,transparentandsocks5(seeHttpProxyServerBootstrap.withSocksServer(boolean)), the modes without a fixed upstream, givenull.- Parameters:
mode- the mode, such asreverse:https://example.com- Returns:
- the reverse proxy mode, or
nullforregular,transparentandsocks5 - Throws:
IllegalArgumentException- for other modes
-
tls
public boolean tls()Returns whether the upstream is reached over TLS (https).- Returns:
- whether the upstream is reached over TLS (
https)
-
rawTcp
public boolean rawTcp()Returns whether client connections are relayed as raw bytes (tcp).- Returns:
- whether client connections are relayed as raw bytes (
tcp)
-
hostAndPort
Returns the upstream ashost:port, with IPv6 addresses in brackets.- Returns:
- the upstream as
host:port, with IPv6 addresses in brackets
-
hostHeader
TheHostfield requests get: the host, with the port unless it is the scheme's default, as mitmproxy'surl.hostportwrites it.- Returns:
- the authority for the
Hostfield
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
scheme
Returns the value of theschemerecord component.- Returns:
- the value of the
schemerecord component
-
host
Returns the value of thehostrecord component.- Returns:
- the value of the
hostrecord component
-
port
public int port()Returns the value of theportrecord component.- Returns:
- the value of the
portrecord component
-