Record Class ReverseProxyMode

java.lang.Object
java.lang.Record
org.microproxy.ReverseProxyMode
Record Components:
scheme - http, https or tcp
host - the upstream host name or IP address (IPv6 without brackets)
port - the upstream port

public record ReverseProxyMode(String scheme, String host, int port) extends Record
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.

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 Details

    • ReverseProxyMode

      public ReverseProxyMode(String scheme, String host, int port)
      Checks the components.
      Parameters:
      scheme - http, https or tcp
      host - the upstream host
      port - the upstream port, 1 to 65535
      Throws:
      IllegalArgumentException - if a component is invalid
  • Method Details

    • parse

      public static ReverseProxyMode parse(String spec)
      Parses an upstream server specification, [scheme://]host[:port]: the scheme defaults to https, the port to 443 for https and 80 for http; tcp needs a port.
      Parameters:
      spec - the upstream, such as https://example.com or http://10.0.0.1:8080
      Returns:
      the reverse proxy mode
      Throws:
      IllegalArgumentException - if the specification is invalid
    • parseMode

      public static ReverseProxyMode parseMode(String mode)
      Parses a mitmproxy-style mode: reverse:<spec> (see parse(java.lang.String)); regular, transparent and socks5 (see HttpProxyServerBootstrap.withSocksServer(boolean)), the modes without a fixed upstream, give null.
      Parameters:
      mode - the mode, such as reverse:https://example.com
      Returns:
      the reverse proxy mode, or null for regular, transparent and socks5
      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

      public String hostAndPort()
      Returns the upstream as host:port, with IPv6 addresses in brackets.
      Returns:
      the upstream as host:port, with IPv6 addresses in brackets
    • hostHeader

      public String hostHeader()
      The Host field requests get: the host, with the port unless it is the scheme's default, as mitmproxy's url.hostport writes it.
      Returns:
      the authority for the Host field
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • scheme

      public String scheme()
      Returns the value of the scheme record component.
      Returns:
      the value of the scheme record component
    • host

      public String host()
      Returns the value of the host record component.
      Returns:
      the value of the host record component
    • port

      public int port()
      Returns the value of the port record component.
      Returns:
      the value of the port record component