Interface HttpProxyServerBootstrap
HttpProxyServer.-
Method Summary
Modifier and TypeMethodDescriptiondefault ChainedProxyManagerThe chained proxy manager configured so far, ornull; lets extensions wrap it.Returns the filters source configured so far (never null).default FrameInterceptorReturns the frame interceptor configured so far, or null.default Http2OptionsReturns the HTTP/2 limits configured so far (never null).default Http3OptionsReturns the HTTP/3 limits configured so far (never null).default QuicFramingReturns the QUIC framing configured so far.default QuicInterceptorReturns the QUIC interceptor configured so far, or null.default ScriptCallObserverReturns the script call observer configured so far, or null.default StatsRegistrygetStats()Returns the registry configured so far:StatsRegistry.NOOPwithout metrics.default TcpInterceptorReturns the TCP interceptor configured so far, or null.default FlowTracerReturns the tracer configured so far:FlowTracer.NOOPwithout one.default UdpInterceptorReturns the UDP interceptor configured so far, or null.default HttpProxyServerBootstraponAllProtocols(Consumer<ProtocolPolicy.Builder> policy) Sets fields of theProtocolPolicyof every client protocol: below each protocol's own (onHttp1(java.util.function.Consumer<org.microproxy.Http1PolicyBuilder>),onHttp2(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>),onHttp3(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)), above the protocols' defaults.default HttpProxyServerBootstraponHttp1(Consumer<Http1PolicyBuilder> policy) Sets fields of theProtocolPolicyof HTTP/1.x clients, which win over those set for every protocol (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)) and over HTTP/1's defaults.default HttpProxyServerBootstraponHttp2(Consumer<ProtocolPolicy.Builder> policy) Sets fields of theProtocolPolicyof HTTP/2 clients (h2 and h2c), which win over those set for every protocol (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)).default HttpProxyServerBootstraponHttp3(Consumer<ProtocolPolicy.Builder> policy) Sets fields of theProtocolPolicyof HTTP/3 clients (the HTTP/3 listener, transparent QUIC, QUIC inside CONNECT-UDP flows), which win over those set for every protocol (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)).plusActivityTracker(ActivityTracker activityTracker) Adds an observer alongside the configured activity trackers.plusFiltersSource(HttpFiltersSource filtersSource) Adds a filters source after those already configured; they run as aHttpFiltersChain.default HttpProxyServerBootstrapplusStrippedRequestHeaders(String... names) Adds to the headers removed from requests sent upstream (seewithStrippedRequestHeaders(java.lang.String...)).start()Starts the proxy with this configuration.withAcceptProxyProtocol(boolean acceptProxyProtocol) Require a PROXY protocol (v1 or v2) header on every inbound connection: the same aswithAcceptProxyProtocol(ProxyProtocolMode)withProxyProtocolMode.REQUIRED, orProxyProtocolMode.OFFforfalse.default HttpProxyServerBootstrapWhether client connections start with a PROXY protocol header (v1 or v2), read before anything else on the connection (before TLS on a TLS listener, before SOCKS or HTTP/2 detection).withAddress(InetSocketAddress address) Sets the proxy listener address.default HttpProxyServerBootstrapwithAdmin(InetSocketAddress address) Serves Envoy's admin API on its own HTTP listener ataddress, apart from the proxy's listeners:/stats,/stats/prometheus,/ready,/server_info,/listeners,/clusters,/config_dump,/logging, and, withPOST,/healthcheck/fail,/healthcheck/ok,/drain_listenersand/quitquitquit;/lists them.default HttpProxyServerBootstrapwithAdminToken(String token) Requirestokenon every admin request but/ready: as a bearer token (Authorization: Bearer <token>), or as the password of basic authentication with any user name (or asuser:passworditself, when the token has a colon).default HttpProxyServerBootstrapwithAllowChunkedLength(boolean allow) Accept HTTP/1.1 requests that carry bothTransfer-EncodingandContent-Length, as RFC 9112 section 6.1 allows a server to: theContent-Lengthis removed, the body is read by its chunked coding alone, and the client connection is closed after the response, so that whatever follows the body is never read as another request.default HttpProxyServerBootstrapwithAllowHosts(String... patterns) Hosts whose TLS connections are intercepted; all others are tunnelled untouched (mitmproxy'sallow_hosts).withAllowLocalOnly(boolean allowLocalOnly) Listen on the loopback interface only.withAllowRequestToOriginServer(boolean allowRequestToOriginServer) Accept origin-form requests (GET /path) as if the proxy were the origin.default HttpProxyServerBootstrapwithAltSvcH3Stripping(boolean strip) Whether to remove HTTP/3 alternatives (h3,h3-29,h3-Q050, ..., and Google QUIC'squic) fromAlt-Svcresponse headers, keeping the other alternatives (such ash2=":443") and their parameters as they are.withAuthenticateSslClients(boolean authenticateSslClients) Require client certificates on the proxy's TLS listener.default HttpProxyServerBootstrapwithChainedProxyRetryBackoff(Duration initial, Duration max) Exponential backoff with full jitter between chained proxy attempts:withChainedProxyRetryBackoff(RetryBackoff.exponentialWithJitter(initial, max)).default HttpProxyServerBootstrapwithChainedProxyRetryBackoff(RetryBackoff backoff) Waits between attempts when a connection through one chained proxy (or the direct fallback) fails and the next candidate from theChainedProxyManageris tried, asbackoffsays:RetryBackoff.exponential(java.time.Duration, java.time.Duration)for exact doubling waits,RetryBackoff.exponentialWithJitter(java.time.Duration, java.time.Duration)for random ones ("full jitter"),RetryBackoff.fixed(java.time.Duration)for the same wait every time.withChainProxyManager(ChainedProxyManager chainProxyManager) Sets the manager selecting upstream proxies.default HttpProxyServerBootstrapwithCommandLineOptions(List<String> options) The command line the proxy was started with, which the admin's/server_infoshows (secret values redacted) as Envoy shows its own; the launcher passes its arguments.withConnectTimeout(int connectTimeoutMs) Connect timeout for outbound connections in milliseconds.default HttpProxyServerBootstrapwithConnectUdp(boolean enabled) Serves CONNECT-UDP (MASQUE, RFC 9298) on a forward proxy's TCP listener, with or without HTTP/3: an extendedCONNECTwith:protocol connect-udpon an HTTP/2 connection (h2 on the TLS listener withwithHttp2(boolean), orh2c), and the HTTP/1.1 form, aGETwithUpgrade: connect-udp.default HttpProxyServerBootstrapwithDrainStrategy(DrainStrategy strategy) How a draining proxy tells clients to go elsewhere (defaultDrainStrategy.GRADUAL, as Envoy's--drain-strategy); seeHttpProxyServer.drain(java.time.Duration).default HttpProxyServerBootstrapwithDrainTime(Duration drainTime) How long exchanges in progress may take to finish when the proxy stops, and how long a drain lasts when the admin's/drain_listeners?gracefulstarts one (default 10 seconds, Envoy's--drain-time-s).withFailureResponder(FailureResponder responder) Makes the proxy's own answers when requests fail (seeProxyFailure): unreachable or misbehaving servers, timeouts, an exhausted connection pool, refused requests.withFiltersSource(HttpFiltersSource filtersSource) Sets the source of per-request filters.default HttpProxyServerBootstrapwithFrameInterceptor(FrameInterceptor interceptor) Shows every HTTP/2 frame the proxy receives or sends, on the client side and on connections to servers, tointerceptor, which may edit, drop and add frames within the rulesFrameInterceptordescribes.default HttpProxyServerBootstrapwithHealthCheckPath(String path, boolean passThrough) Answers health checks on the proxy's own listener, as Envoy's health check filter does: a request forpath(its path without the query, exactly) gets200 OKfrom the proxy, or503withx-envoy-immediate-health-check-fail: truewhile the health check fails or the proxy is draining.default HttpProxyServerBootstrapwithHttp2(boolean enabled) Serves HTTP/2 to clients on intercepted TLS (withManInTheMiddle(org.microproxy.MitmManager)) and the proxy TLS listener (withSslContextSource(org.microproxy.SslContextSource)): the client handshake offersh2andhttp/1.1through ALPN, and a client that picksh2has each of its streams handled as an exchange of its own, concurrently, with the same filters, cache, authentication, failure answers and trackers as HTTP/1 requests.default HttpProxyServerBootstrapwithHttp2Cleartext(boolean enabled) Serves HTTP/2 with prior knowledge (h2c, RFC 9113 section 3.3) on the plain listener: a connection that starts with the HTTP/2 connection preface is served as HTTP/2, its streams being proxy requests like HTTP/1 ones (:schemeand:authorityname the target).default HttpProxyServerBootstrapwithHttp2CleartextOnly(boolean enabled) Serves only HTTP/2 with prior knowledge on the plain listener: aswithHttp2Cleartext(boolean)(which this implies), except that a connection that does not start with the HTTP/2 connection preface is not served as HTTP/1.x but treated as a connection error of typePROTOCOL_ERROR(RFC 9113 section 3.4): it is sentGOAWAYand closed.default HttpProxyServerBootstrapwithHttp2Options(Http2Options options) Limits for HTTP/2 connections (seeHttp2Options); null restores the defaults.default HttpProxyServerBootstrapwithHttp2Upstream(boolean enabled) Speaks HTTP/2 to origin servers that offer it: TLS connections to servers (intercepted HTTPS, and thehttps://requests ofwithTlsOrigination(boolean), secure WebSockets included) offerh2andhttp/1.1through ALPN, and a server that picksh2gets every exchange for it as a stream on one connection, shared by concurrent exchanges up to the server's stream limit; others keep HTTP/1.1.default HttpProxyServerBootstrapwithHttp3(boolean enabled) Serves HTTP/3 (RFC 9114, over QUIC): a UDP listener on the TCP listener's port number takes QUIC connections with ALPNh3, and each request stream is an exchange of its own, concurrently, with the same filters, cache, authentication, failure answers, logging and trackers as HTTP/1 and HTTP/2 requests.default HttpProxyServerBootstrapwithHttp3Options(Http3Options options) Limits and timers for HTTP/3 (seeHttp3Options); null restores the defaults.default HttpProxyServerBootstrapwithHttp3Upstream(boolean enabled) Speaks HTTP/3 to origin servers known to support it, whatever the client spoke: one QUIC connection per server, shared by concurrent exchanges as streams.default HttpProxyServerBootstrapwithHttp3UpstreamHosts(String... patterns) Servers reached over HTTP/3 without waiting for anAlt-Svcadvertisement, on the port of theirhttpsURI: those whosehost:portone of these regular expressions is found in, case-insensitively, as forwithIgnoreHosts(java.lang.String...).withHttpCache(HttpCache cache) Caches responses (HttpCache).withIdleConnectionTimeout(int idleConnectionTimeoutInSeconds) Sets the maximum idle time for client and server connections.withIdleConnectionTimeout(Duration idleConnectionTimeout) Sets the maximum idle time for client and server connections.default HttpProxyServerBootstrapwithIgnoreHosts(String... patterns) Hosts whose TLS connections are never intercepted, but tunnelled untouched, so their clients see the real server's certificate (mitmproxy'signore_hosts).default HttpProxyServerBootstrapwithKeepHostHeader(boolean keep) In reverse proxy mode, keeps theHostfield the client sent instead of setting it to the upstream's (mitmproxy'skeep_host_header).default HttpProxyServerBootstrapSame aswithLittleProxyCompatibility(true).withLittleProxyCompatibility(boolean compatible) MakesProtocolPolicy.littleProxy()the defaults of HTTP/1.x clients' policy, so that the proxy behaves like LittleProxy where MicroProxy deliberately differs, for filters that depend on it.withManInTheMiddle(MitmManager mitmManager) Intercepts CONNECT tunnels withmitmManager.withMaxChunkSize(int maxChunkSize) Largest body piece handed to filters when streaming.withMaxConnections(int maxConnections) Pooled connections in total; default 200.withMaxConnectionsPerHost(int maxConnectionsPerHost) Pooled connections per target (host:port); default 10.withMaxHeaderSize(int maxHeaderSize) Sets the maximum HTTP header section size in bytes.withMaxInitialLineLength(int maxInitialLineLength) Sets the maximum HTTP request or status line length in bytes.withMaxWebSocketFrameBufferSize(int maxBytes) Largest WebSocket frame payload buffered forHttpFilters.webSocketFrameReceived(org.microproxy.http.WebSocketFrame, boolean); larger frames are streamed and reported as truncated.withMaxWebSocketMessageSize(int maxBytes) Largest WebSocket message, in bytes, that the proxy joins from its frames forHttpFilters.filterWebSocketMessage(org.microproxy.http.WebSocketMessage, boolean)or inflates (permessage-deflate) for the frame and message hooks.default HttpProxyServerBootstrapwithMetrics(boolean enabled) Turns metrics on with a registry of the default settings (or keeps the onewithStats(org.microproxy.stats.StatsRegistry)gave), or off.Name used for thread names and logging.withNetworkInterface(InetSocketAddress inetSocketAddress) Local address to bind for outbound connections.default HttpProxyServerBootstrapSame aswithAltSvcH3Stripping(true): clients are not told about HTTP/3 (see there).default HttpProxyServerBootstrapRemoves distributed tracing headers (HttpHeaderNames.TRACING_HEADERS:traceparent,tracestate,baggage, the B3 headers,uber-trace-id,X-Amzn-Trace-Id,X-Cloud-Trace-Context,grpc-trace-bin,sentry-trace) from requests sent upstream, so clients' trace ids and baggage do not leak to servers.withPoolIdleTimeout(Duration idleTimeout) Closes pooled connections idle for longer than this;nullkeeps them.withPoolPerRequestInMitm(boolean poolPerRequestInMitm) WithwithPoolSharedMitmConnections(boolean), leases the server connection per intercepted request rather than per session.withPoolSharedMitmConnections(boolean poolSharedMitmConnections) Lets intercepted (MITM) sessions take their server connection from the pool and return it when the client disconnects, so other clients can reuse it.withPort(int port) Port to listen on; 0 picks an ephemeral port.withProxyAlias(String alias) Name used in theViaheader; defaults to the host name.withProxyAuthenticator(ProxyAuthenticator proxyAuthenticator) Requires clients to authenticate: with Basic credentials by default, or with any scheme throughProxyAuthenticator.authenticate(org.microproxy.http.HttpRequest, FlowContext).default HttpProxyServerBootstrapwithProxyProtocolTrustedSources(String... sources) The peers whose PROXY protocol headers are honored, as IP addresses or CIDR ranges (10.0.0.0/8,192.0.2.10,fd00::/8): the load balancers in front of the proxy.default HttpProxyServerBootstrapwithQuicFraming(QuicFraming framing) Which intercepted QUIC connections' streams aQuicInterceptorthat overridesQuicInterceptor.streamMessage(org.microproxy.quic.QuicMessage, org.microproxy.quic.QuicStreamContext)sees as whole messages, cut by aMessageFramerchosen by ALPN or host; how large a message may be; and the error code a stream is reset with when one is too large.default HttpProxyServerBootstrapwithQuicHosts(String... patterns) Hosts whose intercepted QUIC is relayed stream by stream, as raw QUIC, whatever its ALPN: the QUIC counterpart ofwithTcpHosts(java.lang.String...).default HttpProxyServerBootstrapwithQuicInterceptor(QuicInterceptor interceptor) Shows the streams and datagrams of QUIC connections that the proxy intercepts without speaking their protocol tointerceptor, which may rewrite, drop and add their bytes; seeQuicInterceptor.withRequestHeadTimeout(Duration timeout) Sets the maximum time for an HTTP/1 request head to arrive, from its first byte through the terminating blank line.default HttpProxyServerBootstrapwithReverseProxy(String spec) Runs as a reverse proxy for the upstreamspec, such ashttps://example.com(seeReverseProxyMode.parse(java.lang.String)).default HttpProxyServerBootstrapRuns as a reverse proxy for one upstream server (seeReverseProxyMode);null(the default) is a forward proxy.default HttpProxyServerBootstrapwithScriptCallObserver(ScriptCallObserver observer) Shows every call into a script's hooks toobserver(seeScriptCallObserver): the scripting module (--script) passes it on to the script it loads.withSendProxyProtocol(boolean sendProxyProtocol) Send a PROXY protocol v1 header to the final server: first on a direct connection, or through the tunnel once an HTTP chained proxy has accepted the CONNECT.Selects the shared upstream connection pool implementation.withServerResolver(HostResolver serverResolver) Sets the resolver used for upstream host names.withSharedServerConnectionPool(boolean useSharedServerConnectionPool) Shares server connections between all clients instead of keeping them per client connection.default HttpProxyServerBootstrapwithSocksDetection(boolean detect) Serves SOCKS clients on the listener besides HTTP ones, told apart by their first byte: 5 for SOCKS5, 4 for SOCKS4 and 4a, which no HTTP request starts with.default HttpProxyServerBootstrapwithSocksServer(boolean socks) Makes the listener a SOCKS server (mitmproxy'ssocks5mode): SOCKS5 (RFC 1928), and SOCKS4 and 4a, with theCONNECTcommand only.withSslContextSource(SslContextSource sslContextSource) Serve the proxy itself over TLS (an "HTTPS proxy").default HttpProxyServerBootstrapwithStats(StatsRegistry registry) Keeps the proxy's metrics inregistry: Envoy's stats (http.<name>.*,cluster.<name>.*,listener.<address>.*,server.*, ...; seeStatsRegistry), whichStatsFormatterrenders for Prometheus andStatsdSinkpushes to statsd.default HttpProxyServerBootstrapwithStrippedRequestHeaders(String... names) Removes these headers (case-insensitively) from every request right before it is written upstream: after all filters, so headers that filters added are removed too.default HttpProxyServerBootstrapwithTcpHosts(String... patterns) Hosts whose connections are relayed as raw TCP even when they look like HTTP (mitmproxy'stcp_hosts): plain bytes after aCONNECTare not served as HTTP, and an intercepted TLS session is relayed decrypted rather than served as HTTP, its bytes going through theTCP hooks.default HttpProxyServerBootstrapwithTcpInterceptor(TcpInterceptor interceptor) Shows the bytes of every raw TCP tunnel tointerceptor, which may rewrite, drop and add them (mitmproxy'stcp_messageand related hooks; seeTcpInterceptorfor which tunnels).withThrottling(long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) Global bandwidth limits for server traffic; 0 means unlimited.withTlsHandshakeTimeout(Duration timeout) The longest a TLS handshake may take, with clients and with servers (default 10 seconds; zero for no limit).default HttpProxyServerBootstrapwithTlsOrigination(boolean enabled) Whether a forward proxy fetches anhttps://URI a client asks for directly, rather than throughCONNECT, by opening TLS to the server itself: an absolute-formGET https://example.com/sent in plain HTTP, an HTTP/2 stream with:scheme httpson anh2cconnection or the proxy's TLS listener, or a secure WebSocket (an absolutewss://URI, or extendedCONNECTwith:scheme https).default HttpProxyServerBootstrapwithTlsProtocols(String... protocols) The TLS versions allowed on every TLS socket the proxy creates: its TLS listener (withSslContextSource(org.microproxy.SslContextSource)), both sides of an intercepted session, and connections to TLS chained proxies.default HttpProxyServerBootstrapwithTlsRetryWithoutSni(boolean retry) Whether a TLS handshake with a server that ends with the server's fatalunrecognized_namealert (RFC 6066 section 3, RFC 8446 section 6.2), its answer to a server name (SNI) it does not recognize, is tried once more on a new connection, without SNI.default HttpProxyServerBootstrapwithTracer(FlowTracer tracer) Traces the proxy's exchanges and flows withtracer(seeFlowTracer): themicroproxy-otelmodule's OpenTelemetry tracing and OTLP export, or another.withTransparent(boolean transparent) Transparent proxying: forward messages without addingViaor stripping hop-by-hop headers, and accept TLS connections that arrive without aCONNECT, such as ones a firewall redirects to the proxy.default HttpProxyServerBootstrapwithTransparentQuicPort(int port) Opens a transparent QUIC listener on UDPport(0 for any): the UDP counterpart of transparent TLS, for QUIC (HTTP/3, UDP 443) that a firewall redirects to the proxy, such asiptables -t nat -A PREROUTING -p udp --dport 443 -j REDIRECT --to-ports <port>.default HttpProxyServerBootstrapwithTransparentTlsPort(int port) The port that TLS connections arriving without aCONNECTin transparent mode are routed to, on the host their SNI names (default 443).default HttpProxyServerBootstrapwithUdpInterceptor(UdpInterceptor interceptor) Shows the datagrams of every UDP flow the proxy relays (CONNECT-UDP, MASQUE, on a forward proxy's HTTP/3 listener) tointerceptor, which may rewrite, drop and add them; seeUdpInterceptor.withUseDnsSec(boolean useDnsSec) Resolves server names with the validating DNSSEC resolver (DnssecHostResolver) instead of the system resolver.
-
Method Details
-
withName
Name used for thread names and logging.- Parameters:
name- the name used for logging and thread names- Returns:
- this bootstrap
-
withAddress
Sets the proxy listener address.- Parameters:
address- the proxy listener address- Returns:
- this bootstrap
-
withPort
Port to listen on; 0 picks an ephemeral port.- Parameters:
port- the listening port, or zero for an ephemeral port- Returns:
- this bootstrap
-
withAllowLocalOnly
Listen on the loopback interface only.- Parameters:
allowLocalOnly- whether to listen only on the loopback interface- Returns:
- this bootstrap
-
withSslContextSource
Serve the proxy itself over TLS (an "HTTPS proxy").- Parameters:
sslContextSource- the TLS context provider for the proxy listener- Returns:
- this bootstrap
-
withAuthenticateSslClients
Require client certificates on the proxy's TLS listener.- Parameters:
authenticateSslClients- whether the TLS listener requires client certificates- Returns:
- this bootstrap
-
withProxyAuthenticator
Requires clients to authenticate: with Basic credentials by default, or with any scheme throughProxyAuthenticator.authenticate(org.microproxy.http.HttpRequest, FlowContext).- Parameters:
proxyAuthenticator- the client authentication policy- Returns:
- this bootstrap
-
withChainProxyManager
Sets the manager selecting upstream proxies.- Parameters:
chainProxyManager- the manager selecting upstream proxies- Returns:
- this bootstrap
-
getChainProxyManager
The chained proxy manager configured so far, ornull; lets extensions wrap it.- Returns:
- the configured chained proxy manager, or
null
-
withManInTheMiddle
Intercepts CONNECT tunnels withmitmManager. To decide per client connection (per user, client address, ...), override itsFlowContextoverloads or useMitmManager.perConnection(java.util.function.Function<? super org.microproxy.FlowContext, ? extends org.microproxy.MitmManager>).- Parameters:
mitmManager- the manager providing interception TLS contexts- Returns:
- this bootstrap
-
withFiltersSource
Sets the source of per-request filters.- Parameters:
filtersSource- the source of per-request filters- Returns:
- this bootstrap
-
plusFiltersSource
Adds a filters source after those already configured; they run as aHttpFiltersChain.- Parameters:
filtersSource- the source of per-request filters- Returns:
- this bootstrap
-
getFiltersSource
HttpFiltersSource getFiltersSource()Returns the filters source configured so far (never null).- Returns:
- the filters source configured so far (never null)
-
withHttpCache
Caches responses (HttpCache). The cache always runs after the filters sources, whichever order they were configured in.- Parameters:
cache- the HTTP cache to use- Returns:
- this bootstrap
-
withStats
Keeps the proxy's metrics inregistry: Envoy's stats (http.<name>.*,cluster.<name>.*,listener.<address>.*,server.*, ...; seeStatsRegistry), whichStatsFormatterrenders for Prometheus andStatsdSinkpushes to statsd. Thehttpstats are named afterthe proxy's name.StatsRegistry.NOOP(the default) turns metrics off, which costs nothing.- Parameters:
registry- the registry, shared with whatever else counts into it- Returns:
- this bootstrap
-
withMetrics
Turns metrics on with a registry of the default settings (or keeps the onewithStats(org.microproxy.stats.StatsRegistry)gave), or off.- Parameters:
enabled- whether to keep metrics- Returns:
- this bootstrap
-
getStats
Returns the registry configured so far:StatsRegistry.NOOPwithout metrics.- Returns:
- the registry configured so far:
StatsRegistry.NOOPwithout metrics
-
withTracer
Traces the proxy's exchanges and flows withtracer(seeFlowTracer): themicroproxy-otelmodule's OpenTelemetry tracing and OTLP export, or another.FlowTracer.NOOP(the default) traces nothing, and costs nothing. The proxy closes the tracer when it stops.- Parameters:
tracer- the tracer- Returns:
- this bootstrap
-
getTracer
Returns the tracer configured so far:FlowTracer.NOOPwithout one.- Returns:
- the tracer configured so far:
FlowTracer.NOOPwithout one
-
withFailureResponder
Makes the proxy's own answers when requests fail (seeProxyFailure): unreachable or misbehaving servers, timeouts, an exhausted connection pool, refused requests. Filters'HttpFilters.proxyToServerFailure(org.microproxy.ProxyFailure)answers take precedence;null(the default) or a responder returningnullkeeps the proxy's plain-text answers.- Parameters:
responder- the function creating a rejection or failure response- Returns:
- this bootstrap
-
withTransparent
Transparent proxying: forward messages without addingViaor stripping hop-by-hop headers, and accept TLS connections that arrive without aCONNECT, such as ones a firewall redirects to the proxy. Such a connection is routed by itsClientHello's server name (SNI) to that host's port 443 (seewithTransparentTlsPort(int)), and is intercepted or tunnelled as aCONNECTto that host would be. Java cannot read a redirected connection's original destination address, so a ClientHello without SNI cannot be routed: the connection is refused with a TLSunrecognized_namealert. Plain HTTP is routed by itsHostfield whenwithAllowRequestToOriginServer(boolean)allows origin-form requests.- Parameters:
transparent- whether to proxy transparently- Returns:
- this bootstrap
-
withTransparentTlsPort
The port that TLS connections arriving without aCONNECTin transparent mode are routed to, on the host their SNI names (default 443).- Parameters:
port- the server port, 1 to 65535- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if the port is out of range
-
withTransparentQuicPort
Opens a transparent QUIC listener on UDPport(0 for any): the UDP counterpart of transparent TLS, for QUIC (HTTP/3, UDP 443) that a firewall redirects to the proxy, such asiptables -t nat -A PREROUTING -p udp --dport 443 -j REDIRECT --to-ports <port>. Needs transparent mode and the optionalquicandhttp3-codecmodules.Java cannot read a redirected datagram's original destination either, so each new client flow (a client address and the Destination Connection ID of its Initial packets) is routed by the SNI of the ClientHello in its Initial packets, which the proxy decrypts, to that host's transparent TLS port. The rules and hooks that decide on TLS decide on it too: ignored and allowed hosts,
HttpFilters.proxyToServerAllowMitm()andHttpFilters.proxyToServerAllowMitm(ClientHello)on aCONNECTthe proxy makes up, andMitmManager.shouldIntercept(org.microproxy.ClientHello, org.microproxy.FlowContext). An intercepted client offering ALPNh3gets a certificate theCertificateAuthorityMitmManagerissues for its SNI and is served HTTP/3 like any client, with its requests going to that host (over HTTP/3 withwithHttp3Upstream(boolean), else over TCP). Everything else (no MITM manager, a declined or ignored host, other ALPN protocols) is relayed untouched to the server as UDP, from a socket per flow, until the flow is idle forHttp3Options.transparentRelayIdleTimeout().- Parameters:
port- the UDP port, 0 for any- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if the port is out of range- See Also:
-
withIgnoreHosts
Hosts whose TLS connections are never intercepted, but tunnelled untouched, so their clients see the real server's certificate (mitmproxy'signore_hosts). Each pattern is a regular expression searched for, ignoring case, inhost:portnames of the connection: theCONNECTtarget and the client's SNI with that port. For example,example\.comignoresexample.com:443andwww.example.com:443;^example\.com:443$ignores only that one. A connection whoseCONNECTtarget matches is tunnelled without waiting for its ClientHello. Replaces earlier patterns; none by default. Only matters with aMITM manager.- Parameters:
patterns- the regular expressions- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if a pattern is not a valid regular expression
-
withAllowHosts
Hosts whose TLS connections are intercepted; all others are tunnelled untouched (mitmproxy'sallow_hosts). Patterns are matched as forwithIgnoreHosts(java.lang.String...), which still applies to the allowed hosts. Replaces earlier patterns; none (everything allowed) by default.- Parameters:
patterns- the regular expressions- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if a pattern is not a valid regular expression
-
withReverseProxy
Runs as a reverse proxy for one upstream server (seeReverseProxyMode);null(the default) is a forward proxy.- Parameters:
mode- the upstream, ornull- Returns:
- this bootstrap
-
withReverseProxy
Runs as a reverse proxy for the upstreamspec, such ashttps://example.com(seeReverseProxyMode.parse(java.lang.String)).- Parameters:
spec- the upstream,[scheme://]host[:port]- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if the specification is invalid
-
withSocksServer
Makes the listener a SOCKS server (mitmproxy'ssocks5mode): SOCKS5 (RFC 1928), and SOCKS4 and 4a, with theCONNECTcommand only. With aproxy authenticator, SOCKS5 clients authenticate with a username and password (RFC 1929), which the authenticator sees asProxy-Authorization: Basic; a client without credentials, SOCKS4's included, may proceed only if the authenticator accepts a request without them.Each request is served as a
CONNECTto its destination would be, aCONNECTthat filters and trackers see but that the client never sent: routing and chained proxies, the server connection, then the client's first bytes decide (seeHttpFilters.proxyToServerAllowMitm(ClientHello)): TLS is intercepted or tunnelled, plain HTTP is served as HTTP, through the filters, even without aMITM manager, and anything else is tunnelled. The client is answered once the server is connected, with a reply code that tells why it could not be.FlowContext.socksVersion()tells such clients apart. Off by default; starting fails withwithReverseProxy(org.microproxy.ReverseProxyMode)orwithSslContextSource(org.microproxy.SslContextSource).- Parameters:
socks- whether the listener serves SOCKS clients only- Returns:
- this bootstrap
-
withSocksDetection
Serves SOCKS clients on the listener besides HTTP ones, told apart by their first byte: 5 for SOCKS5, 4 for SOCKS4 and 4a, which no HTTP request starts with. They are served as withwithSocksServer(boolean), and not with a reverse proxy or a TLS listener either. Off by default.- Parameters:
detect- whether to serve SOCKS clients too- Returns:
- this bootstrap
-
withKeepHostHeader
In reverse proxy mode, keeps theHostfield the client sent instead of setting it to the upstream's (mitmproxy'skeep_host_header). Off by default.- Parameters:
keep- whether to keep the client'sHost- Returns:
- this bootstrap
-
withIdleConnectionTimeout
Sets the maximum idle time for client and server connections.- Parameters:
idleConnectionTimeoutInSeconds- the maximum idle time in seconds- Returns:
- this bootstrap
-
withIdleConnectionTimeout
Sets the maximum idle time for client and server connections.- Parameters:
idleConnectionTimeout- the maximum time a connection may remain idle- Returns:
- this bootstrap
-
withRequestHeadTimeout
Sets the maximum time for an HTTP/1 request head to arrive, from its first byte through the terminating blank line. A timed-out request receives408 Request Timeout; the connection is closed. Zero disables the deadline. The default is 30 seconds. An HTTP/1 protocol policy may override this value withHttp1PolicyBuilder.requestHeadTimeout(java.time.Duration).- Parameters:
timeout- the maximum request-head time, or zero for no deadline- Returns:
- this bootstrap
-
withConnectTimeout
Connect timeout for outbound connections in milliseconds.- Parameters:
connectTimeoutMs- the outbound connect timeout in milliseconds; zero uses the system default- Returns:
- this bootstrap
-
withTlsHandshakeTimeout
The longest a TLS handshake may take, with clients and with servers (default 10 seconds; zero for no limit). The idle timeout alone does not bound it, since it restarts with every byte received.- Parameters:
timeout- the maximum TLS handshake duration- Returns:
- this bootstrap
-
withTlsProtocols
The TLS versions allowed on every TLS socket the proxy creates: its TLS listener (withSslContextSource(org.microproxy.SslContextSource)), both sides of an intercepted session, and connections to TLS chained proxies. DefaultTLSv1.3andTLSv1.2. Each socket enables those of them that itsSSLContextsupports; if it supports none, the handshake fails with an error naming both lists. The protocols are set right after the socket is created, beforeSslContextSource.configure(javax.net.ssl.SSLSocket, boolean),MitmManager.configureServerSocket(javax.net.ssl.SSLSocket, FlowContext)orSslContextSource.configure(javax.net.ssl.SSLSocket, boolean)run, so a hook that sets its own protocols wins. No protocols leaves every context's own defaults; the JDK'sjdk.tls.disabledAlgorithmsapplies either way.- Parameters:
protocols- the enabled TLS protocol names, such asTLSv1.3- Returns:
- this bootstrap
-
withTlsRetryWithoutSni
Whether a TLS handshake with a server that ends with the server's fatalunrecognized_namealert (RFC 6066 section 3, RFC 8446 section 6.2), its answer to a server name (SNI) it does not recognize, is tried once more on a new connection, without SNI. Some misconfigured servers answer so for names they do serve; the JDK'sHttpsURLConnectiononce retried the same way, and LittleProxy forks copied it.Only the SNI extension is left out: the retry offers the same versions and ALPN protocols, and the certificate is validated with the same trust and checked against the same host name as the first attempt's. SNI authenticates nothing, so leaving it out weakens no check; the server may present another (default) certificate, which must then pass the same checks. The retry is logged, and counted in the cluster's
ssl.retry_without_sni; a retry that fails too fails the request as the first attempt would have. Each new connection to such a server pays the extra handshake: nothing is remembered about the server. It applies to servers (intercepted sessions, TLS origination, a reverse proxy'shttps://upstream), not to TLS chained proxies, and not to HTTP/3.Off by default, so that a server that rejects its name fails visibly, as it does for browsers and the JDK's
HttpClient, and the proxy never sends a ClientHello other than the one asked for; on by default for HTTP/1 clients withwithLittleProxyCompatibility(boolean). This sets the field for every client protocol (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>),ProtocolPolicy.tlsRetryWithoutSni()), where it wins over that preset; a protocol's own policy (onHttp1(java.util.function.Consumer<org.microproxy.Http1PolicyBuilder>), ...) wins over it.- Parameters:
retry- whether to retry without SNI after anunrecognized_namealert- Returns:
- this bootstrap
-
onAllProtocols
Sets fields of theProtocolPolicyof every client protocol: below each protocol's own (onHttp1(java.util.function.Consumer<org.microproxy.Http1PolicyBuilder>),onHttp2(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>),onHttp3(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)), above the protocols' defaults. Calls add up: a later one overwrites only the fields it sets. The bootstrap's setters for those fields (withTlsRetryWithoutSni(boolean)) set them here too.bootstrap.onAllProtocols(p -> p.tlsRetryWithoutSni(true));- Parameters:
policy- sets fields on the builder it is given- Returns:
- this bootstrap
-
onHttp1
Sets fields of theProtocolPolicyof HTTP/1.x clients, which win over those set for every protocol (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)) and over HTTP/1's defaults. The builder also takes the fields only HTTP/1 has (Http1PolicyBuilder.allowChunkedLength(boolean)). Calls add up: a later one overwrites only the fields it sets.bootstrap.onHttp1(p -> p.preset(ProtocolPolicy.littleProxy()).filterConnectAnswer(true));- Parameters:
policy- sets fields on the builder it is given- Returns:
- this bootstrap
-
onHttp2
Sets fields of theProtocolPolicyof HTTP/2 clients (h2 and h2c), which win over those set for every protocol (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)). Calls add up.- Parameters:
policy- sets fields on the builder it is given- Returns:
- this bootstrap
-
onHttp3
Sets fields of theProtocolPolicyof HTTP/3 clients (the HTTP/3 listener, transparent QUIC, QUIC inside CONNECT-UDP flows), which win over those set for every protocol (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)). Calls add up.- Parameters:
policy- sets fields on the builder it is given- Returns:
- this bootstrap
-
withLittleProxyCompatibility
MakesProtocolPolicy.littleProxy()the defaults of HTTP/1.x clients' policy, so that the proxy behaves like LittleProxy where MicroProxy deliberately differs, for filters that depend on it. LittleProxy only ever spoke HTTP/1.x: HTTP/2 and HTTP/3 clients keep MicroProxy's defaults unless their own policies say otherwise (onHttp2(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>),onHttp3(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>)). Every field set explicitly, for HTTP/1 (onHttp1(java.util.function.Consumer<org.microproxy.Http1PolicyBuilder>)) or for all protocols (onAllProtocols(java.util.function.Consumer<org.microproxy.ProtocolPolicy.Builder>),withTlsRetryWithoutSni(boolean)), wins over the preset. The fields and their LittleProxy sources are listed atProtocolPolicy.littleProxy():- the server is resolved before
HttpFilters.proxyToServerRequest(org.microproxy.http.HttpObject), and a name that does not resolve gets502without that hook being called; - the
200 Connection establishedanswer to a client'sCONNECTis written without going throughHttpFilters.serverToProxyResponse(org.microproxy.http.HttpObject)andHttpFilters.proxyToClientResponse(org.microproxy.http.HttpObject); trackers are still told (ActivityTracker.responseSentToClient(org.microproxy.FlowContext, org.microproxy.http.HttpResponse)), andHttpFilters.proxyToClientResponseSent(org.microproxy.http.HttpResponse, org.microproxy.ResponseSource)andHttpFilters.exchangeEnded(boolean)still run; - plain HTTP sent after a
CONNECTthat could be intercepted is relayed as raw bytes rather than served as HTTP; - a PROXY header sent without one received (
withSendProxyProtocol(boolean)) names the server connection's remote address as its destination, not the address the client connected to, and none is sent when the client and that address are of different address families; - a server that rejects the server name the proxy sends with an
unrecognized_namealert is tried again without SNI (withTlsRetryWithoutSni(boolean)); - the TLS handshake with the server of an intercepted
CONNECTruns before theCONNECTis answered (MitmServerHandshake.EAGER), so a failure answers it502.
HttpFilters.proxyToClientResponse(org.microproxy.http.HttpObject)may replace the proxy's own responses, as in LittleProxy 2.x and by default (GeneratedResponses.REPLACEABLE); forks of LittleProxy 1.x let it change them in place only, whichonHttp1(p -> p.generatedResponses(GeneratedResponses.IN_PLACE))restores.Security fixes (strict request parsing, error pages that do not echo the request) are not affected. Off by default.
- Parameters:
compatible- whether HTTP/1's defaults are LittleProxy's- Returns:
- this bootstrap
- the server is resolved before
-
withLittleProxyCompatibility
Same aswithLittleProxyCompatibility(true).- Returns:
- this bootstrap
-
withServerResolver
Sets the resolver used for upstream host names.- Parameters:
serverResolver- the resolver for upstream host names- Returns:
- this bootstrap
-
withStrippedRequestHeaders
Removes these headers (case-insensitively) from every request right before it is written upstream: after all filters, so headers that filters added are removed too. It applies to plain requests, requests inside intercepted (MITM) sessions, upgrade requests, and theCONNECTrequests sent to HTTP chained proxies; the bytes of an uninspected tunnel are never touched. Replaces the names set so far; no names turns it off.- Parameters:
names- the request header names to strip before forwarding- Returns:
- this bootstrap
-
plusStrippedRequestHeaders
Adds to the headers removed from requests sent upstream (seewithStrippedRequestHeaders(java.lang.String...)).- Parameters:
names- the additional request header names to strip before forwarding- Returns:
- this bootstrap
-
withoutTracingHeadersUpstream
Removes distributed tracing headers (HttpHeaderNames.TRACING_HEADERS:traceparent,tracestate,baggage, the B3 headers,uber-trace-id,X-Amzn-Trace-Id,X-Cloud-Trace-Context,grpc-trace-bin,sentry-trace) from requests sent upstream, so clients' trace ids and baggage do not leak to servers. Adds toplusStrippedRequestHeaders(java.lang.String...).- Returns:
- this bootstrap
-
withAltSvcH3Stripping
Whether to remove HTTP/3 alternatives (h3,h3-29,h3-Q050, ..., and Google QUIC'squic) fromAlt-Svcresponse headers, keeping the other alternatives (such ash2=":443") and their parameters as they are. A header left with no alternative is removed;Alt-Svc: clearis never touched.A client that learns an origin speaks HTTP/3 may move to QUIC over UDP, which bypasses the proxy: browsers never send QUIC through an HTTP proxy, and a transparent deployment often redirects only TCP. Where the proxy is meant to see the traffic, that is a hole, so this is on by default when
interceptionortransparent modeis configured, and off otherwise; except, with a transparent QUIC listener, for clients whose traffic was redirected to the proxy, whose QUIC reaches it too. Clients can still learn about HTTP/3 from DNSHTTPSrecords, so transparent deployments without a QUIC listener should also block UDP port 443, which makes clients fall back to TCP. Setting this applies to every client.Responses from servers are rewritten before
HttpFilters.proxyToClientResponse(org.microproxy.http.HttpObject)sees them; short-circuit responses from filters (and the cache) after it.- Parameters:
strip- whether to remove HTTP/3 and QUIC advertisements from Alt-Svc headers- Returns:
- this bootstrap
-
withoutHttp3Advertisement
Same aswithAltSvcH3Stripping(true): clients are not told about HTTP/3 (see there).- Returns:
- this bootstrap
-
withChainedProxyRetryBackoff
Waits between attempts when a connection through one chained proxy (or the direct fallback) fails and the next candidate from theChainedProxyManageris tried, asbackoffsays:RetryBackoff.exponential(java.time.Duration, java.time.Duration)for exact doubling waits,RetryBackoff.exponentialWithJitter(java.time.Duration, java.time.Duration)for random ones ("full jitter"),RetryBackoff.fixed(java.time.Duration)for the same wait every time. It never waits before the first attempt or after the last, stops waiting (and gives up on the request) when the client disconnects meanwhile, and by default waits at most 30 seconds or the connect timeout in total per request, whichever is less; once that is spent, the remaining candidates are tried without waiting. The policy can set another budget (RetryBackoff.withBudget(java.time.Duration)) or none (RetryBackoff.unbudgeted()), to wait every time it names as LittleProxy forks that added a backoff did. The wait counts towards the connect phase ofFlowContext.timings(). A request's filters can choose another backoff (HttpFilters.chainedProxyRetryBackoff()). Off (RetryBackoff.none()) by default, as in LittleProxy, which tries the next chained proxy at once;nullturns it off again.- Parameters:
backoff- the backoff between attempts, ornullfor none- Returns:
- this bootstrap
-
withChainedProxyRetryBackoff
Exponential backoff with full jitter between chained proxy attempts:withChainedProxyRetryBackoff(RetryBackoff.exponentialWithJitter(initial, max)). Before attemptn + 1the proxy waits a random time between zero andinitial * 2^(n-1), capped atmax. Anullmaximum is the initial wait; anullinitial wait turns the backoff off. For exact, unjittered waits usewithChainedProxyRetryBackoff(RetryBackoff)withRetryBackoff.exponential(java.time.Duration, java.time.Duration).- Parameters:
initial- the ceiling of the delay before the first retrymax- the ceiling of every retry delay- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- ifinitialis not positive ormaxis below it
-
withHttp2
Serves HTTP/2 to clients on intercepted TLS (withManInTheMiddle(org.microproxy.MitmManager)) and the proxy TLS listener (withSslContextSource(org.microproxy.SslContextSource)): the client handshake offersh2andhttp/1.1through ALPN, and a client that picksh2has each of its streams handled as an exchange of its own, concurrently, with the same filters, cache, authentication, failure answers and trackers as HTTP/1 requests. Requests reach servers as HTTP/1.1, each stream on a server connection of its own, unlesswithHttp2Upstream(boolean)lets them share an HTTP/2 connection (as it does by default). Limits are set withwithHttp2Options(org.microproxy.Http2Options).On by default when the optional
http2-codecmodule is on the class path;falseoffers clients HTTP/1.1 only. Without the module, a server left at the default speaks HTTP/1.1 to clients (and logs so once), while starting one withtruefails withIllegalStateException.- Parameters:
enabled- whether the feature is enabled- Returns:
- this bootstrap
-
withHttp2Upstream
Speaks HTTP/2 to origin servers that offer it: TLS connections to servers (intercepted HTTPS, and thehttps://requests ofwithTlsOrigination(boolean), secure WebSockets included) offerh2andhttp/1.1through ALPN, and a server that picksh2gets every exchange for it as a stream on one connection, shared by concurrent exchanges up to the server's stream limit; others keep HTTP/1.1. Independent ofwithHttp2(boolean), which is about clients.On by default when the optional
http2-codecmodule is on the class path;falseoffers servers HTTP/1.1 only. Without the module, a server left at the default speaks HTTP/1.1 to servers (and logs so once), while starting one withtruefails withIllegalStateException.- Parameters:
enabled- whether the feature is enabled- Returns:
- this bootstrap
-
withHttp2Cleartext
Serves HTTP/2 with prior knowledge (h2c, RFC 9113 section 3.3) on the plain listener: a connection that starts with the HTTP/2 connection preface is served as HTTP/2, its streams being proxy requests like HTTP/1 ones (:schemeand:authorityname the target). Other connections stay HTTP/1.x;Upgrade: h2cis not supported. Off by default; limits are set withwithHttp2Options(org.microproxy.Http2Options).Needs the optional
http2-codecmodule on the class path: starting a server with it enabled without the module fails withIllegalStateException.- Parameters:
enabled- whether the feature is enabled- Returns:
- this bootstrap
-
withHttp2CleartextOnly
Serves only HTTP/2 with prior knowledge on the plain listener: aswithHttp2Cleartext(boolean)(which this implies), except that a connection that does not start with the HTTP/2 connection preface is not served as HTTP/1.x but treated as a connection error of typePROTOCOL_ERROR(RFC 9113 section 3.4): it is sentGOAWAYand closed. For a listener only HTTP/2 clients use, such as a reverse proxy in front of gRPC servers. Off by default.A server with it fails to start with a TLS listener (
withSslContextSource(org.microproxy.SslContextSource)), SOCKS (withSocksServer(boolean),withSocksDetection(boolean)), transparent mode or atcp://reverse proxy, which all need connections that are not HTTP/2; and, likewithHttp2Cleartext(boolean), without the optionalhttp2-codecmodule.- Parameters:
enabled- whether the feature is enabled- Returns:
- this bootstrap
-
getHttp2Options
Returns the HTTP/2 limits configured so far (never null).- Returns:
- the HTTP/2 limits configured so far (never null)
-
withHttp2Options
Limits for HTTP/2 connections (seeHttp2Options); null restores the defaults.- Parameters:
options- the HTTP/2 connection limits- Returns:
- this bootstrap
-
withHttp3
Serves HTTP/3 (RFC 9114, over QUIC): a UDP listener on the TCP listener's port number takes QUIC connections with ALPNh3, and each request stream is an exchange of its own, concurrently, with the same filters, cache, authentication, failure answers, logging and trackers as HTTP/1 and HTTP/2 requests. Off by default; limits are set withwithHttp3Options(org.microproxy.Http3Options).A reverse proxy (
withReverseProxy(org.microproxy.ReverseProxyMode)) serves its upstream this way: requests reach it as HTTP/1.1, HTTP/2 (withHttp2Upstream(boolean)) or HTTP/3 (withHttp3Upstream(boolean)), as it speaks, and responses sent over TCP advertise the listener withAlt-Svc: h3=":<port>"(seeHttp3Options.Builder.altSvc).A forward proxy serves HTTP/3 next to its own TLS listener (
withSslContextSource(org.microproxy.SslContextSource)), to clients that know it does, such as MASQUE clients: requests name their targets with:schemeand:authority,CONNECT(RFC 9114 section 4.4) opens a tunnel as an HTTP/1 or HTTP/2 one does, and CONNECT-UDP (RFC 9298) proxies UDP in HTTP Datagrams (seeHttp3Options.Builder.connectUdpTemplate), here and, aswithConnectUdp(boolean)describes, on the TCP listener. Every HTTP/3 connection to clients takes WebSockets over extendedCONNECT(RFC 9220).The listener presents the certificate of the proxy's TLS listener, which must provide it as
KeyMaterial(SslContextSource.getKeyMaterial(java.lang.String)), or, for a reverse proxy without a TLS listener, one that aCertificateAuthorityMitmManagerissues for the name the client asks for. A forward proxy without a TLS listener, a transparent proxy (its clients' QUIC goes towithTransparentQuicPort(int)) and areverse:tcp://proxy fail to start with HTTP/3 enabled.Needs the optional
quicandhttp3-codecmodules on the class path: starting a server with HTTP/3 enabled without them fails withIllegalStateException.- Parameters:
enabled- whether the feature is enabled- Returns:
- this bootstrap
-
withHttp3Upstream
Speaks HTTP/3 to origin servers known to support it, whatever the client spoke: one QUIC connection per server, shared by concurrent exchanges as streams. A server is known to support HTTP/3 once one of its responses over TLS advertisedh3on the same host inAlt-Svc(remembered for itsma, and learned before the advertisement is removed for clients), or when its host matcheswithHttp3UpstreamHosts(java.lang.String...). A QUIC handshake that fails or takes longer thanHttp3Options.upstreamHandshakeTimeout()sends the request over TCP instead, and keeps the server on TCP forHttp3Options.upstreamFailureTimeout(). Only direct connections use HTTP/3: not those through chained proxies or tunnels, nor those with a PROXY protocol header. Off by default.Servers are validated with the MITM manager's trust (
MitmManager.serverTrustManager(java.lang.String, int, org.microproxy.FlowContext)), or the JDK's default trust store without one.Needs the optional
quicandhttp3-codecmodules on the class path: starting a server with it enabled without them fails withIllegalStateException.- Parameters:
enabled- whether the feature is enabled- Returns:
- this bootstrap
-
withHttp3UpstreamHosts
Servers reached over HTTP/3 without waiting for anAlt-Svcadvertisement, on the port of theirhttpsURI: those whosehost:portone of these regular expressions is found in, case-insensitively, as forwithIgnoreHosts(java.lang.String...). Takes effect withwithHttp3Upstream(boolean); replaces any previous patterns, and none (the default) relies onAlt-Svcalone.- Parameters:
patterns- regular expressions forhost:portnames- Returns:
- this bootstrap
-
getHttp3Options
Returns the HTTP/3 limits configured so far (never null).- Returns:
- the HTTP/3 limits configured so far (never null)
-
withHttp3Options
Limits and timers for HTTP/3 (seeHttp3Options); null restores the defaults.- Parameters:
options- the HTTP/3 options- Returns:
- this bootstrap
-
withConnectUdp
Serves CONNECT-UDP (MASQUE, RFC 9298) on a forward proxy's TCP listener, with or without HTTP/3: an extendedCONNECTwith:protocol connect-udpon an HTTP/2 connection (h2 on the TLS listener withwithHttp2(boolean), orh2c), and the HTTP/1.1 form, aGETwithUpgrade: connect-udp. UDP payloads travel both ways in DATAGRAM capsules on the stream (RFC 9297 section 3.5). A forward proxy withwithHttp3(boolean)serves CONNECT-UDP on its HTTP/3 listener and on its TCP listener whether or not this is set. The template, bounds and QUIC inspection areHttp3Options's (Http3Options.Builder.connectUdpTemplateand the rest). Off by default.A reverse proxy fails to start with it. Needs the optional
quicandhttp3-codecmodules on the class path: starting a server with it enabled without them fails withIllegalStateException.- Parameters:
enabled- whether the feature is enabled- Returns:
- this bootstrap
-
withFrameInterceptor
Shows every HTTP/2 frame the proxy receives or sends, on the client side and on connections to servers, tointerceptor, which may edit, drop and add frames within the rulesFrameInterceptordescribes. One per proxy: a later call replaces it, and null removes it. Without one (the default), frames cost nothing extra. It takes effect where HTTP/2 is enabled (withHttp2(boolean),withHttp2Upstream(boolean),withHttp2Cleartext(boolean)), and sees HTTP/3 frames where HTTP/3 is (withHttp3(boolean),withHttp3Upstream(boolean)); other HTTP/3 traffic reaches an interceptor through anHttp3FramePipeline.- Parameters:
interceptor- the interceptor, or null for none- Returns:
- this bootstrap
-
getFrameInterceptor
Returns the frame interceptor configured so far, or null.- Returns:
- the frame interceptor configured so far, or null
-
withScriptCallObserver
Shows every call into a script's hooks toobserver(seeScriptCallObserver): the scripting module (--script) passes it on to the script it loads. One per proxy: a later call replaces it, and null removes it.- Parameters:
observer- the observer, or null for none- Returns:
- this bootstrap
-
getScriptCallObserver
Returns the script call observer configured so far, or null.- Returns:
- the script call observer configured so far, or null
-
withTcpInterceptor
Shows the bytes of every raw TCP tunnel tointerceptor, which may rewrite, drop and add them (mitmproxy'stcp_messageand related hooks; seeTcpInterceptorfor which tunnels). One per proxy: a later call replaces it, and null removes it. Without one (the default), tunnels copy bytes through pooled buffers and cost nothing extra.With an interceptor, TLS that does not carry HTTP is intercepted too, so the hooks see it decrypted: a client whose ALPN offers only other protocols (
imap,mqtt, ...) is intercepted, the server being offered the same protocols and the client getting the server's choice, rather than tunnelled (unless the other rules decline it;acme-tls/1never is). Whatever the interceptor, an intercepted session is relayed as raw TCP rather than served as HTTP when its ALPN protocol is not HTTP's, when its host is a TCP host, or, without ALPN, when its decrypted bytes do not start like an HTTP request or its server speaks first (an SMTP banner).- Parameters:
interceptor- the interceptor, or null for none- Returns:
- this bootstrap
-
getTcpInterceptor
Returns the TCP interceptor configured so far, or null.- Returns:
- the TCP interceptor configured so far, or null
-
withUdpInterceptor
Shows the datagrams of every UDP flow the proxy relays (CONNECT-UDP, MASQUE, on a forward proxy's HTTP/3 listener) tointerceptor, which may rewrite, drop and add them; seeUdpInterceptor. One per proxy: a later call replaces it, and null removes it.- Parameters:
interceptor- the interceptor, or null for none- Returns:
- this bootstrap
-
getUdpInterceptor
Returns the UDP interceptor configured so far, or null.- Returns:
- the UDP interceptor configured so far, or null
-
withTcpHosts
Hosts whose connections are relayed as raw TCP even when they look like HTTP (mitmproxy'stcp_hosts): plain bytes after aCONNECTare not served as HTTP, and an intercepted TLS session is relayed decrypted rather than served as HTTP, its bytes going through theTCP hooks. TLS is still intercepted, as for other hosts; usewithIgnoreHosts(java.lang.String...)to leave it untouched. Each pattern is a regular expression searched for, ignoring case, in the target's host name and in the client's SNI (without the port, as mitmproxy matches them). Replaces earlier patterns; none by default.- Parameters:
patterns- the regular expressions- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if a pattern is not a valid regular expression
-
withQuicInterceptor
Shows the streams and datagrams of QUIC connections that the proxy intercepts without speaking their protocol tointerceptor, which may rewrite, drop and add their bytes; seeQuicInterceptor. One per proxy: a later call replaces it, and null removes it.With an interceptor, transparent QUIC (and QUIC inside CONNECT-UDP flows, with
Http3Options.Builder.connectUdpInterceptQuic) whose ClientHello offers no HTTP/3 is intercepted, rather than relayed untouched, unless the host rules,MitmManager.shouldIntercept(org.microproxy.ClientHello, org.microproxy.FlowContext)or the filters decline it: the proxy terminates the client's QUIC with a certificate its CA issues, connects to the server with the client's ALPN protocols, and relays each stream through the hooks. HTTP/3 is still served as HTTP/3, except for the QUIC hosts.- Parameters:
interceptor- the interceptor, or null for none- Returns:
- this bootstrap
-
getQuicInterceptor
Returns the QUIC interceptor configured so far, or null.- Returns:
- the QUIC interceptor configured so far, or null
-
withQuicFraming
Which intercepted QUIC connections' streams aQuicInterceptorthat overridesQuicInterceptor.streamMessage(org.microproxy.quic.QuicMessage, org.microproxy.quic.QuicStreamContext)sees as whole messages, cut by aMessageFramerchosen by ALPN or host; how large a message may be; and the error code a stream is reset with when one is too large.QuicFraming.defaults()(DNS over QUIC with its two-byte length prefix) by default.- Parameters:
framing- the framing- Returns:
- this bootstrap
-
getQuicFraming
Returns the QUIC framing configured so far.- Returns:
- the QUIC framing configured so far
-
withQuicHosts
Hosts whose intercepted QUIC is relayed stream by stream, as raw QUIC, whatever its ALPN: the QUIC counterpart ofwithTcpHosts(java.lang.String...). Their HTTP/3 is not served as HTTP/3 (filters and frame hooks do not see it); its streams go through theQUIC hooks, as other protocols' do, and QUIC that offers no HTTP/3 is intercepted even without an interceptor. The other rules still decide whether to intercept at all; usewithIgnoreHosts(java.lang.String...)to relay a host untouched. Each pattern is a regular expression searched for, ignoring case, in the server's host name and in the client's SNI (without the port). Replaces earlier patterns; none by default.- Parameters:
patterns- the regular expressions- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if a pattern is not a valid regular expression
-
plusActivityTracker
Adds an observer alongside the configured activity trackers.- Parameters:
activityTracker- the observer to add- Returns:
- this bootstrap
-
withThrottling
HttpProxyServerBootstrap withThrottling(long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) Global bandwidth limits for server traffic; 0 means unlimited.- Parameters:
readThrottleBytesPerSecond- the inbound bandwidth limit in bytes per second, or zero for unlimitedwriteThrottleBytesPerSecond- the outbound bandwidth limit in bytes per second, or zero for unlimited- Returns:
- this bootstrap
-
withNetworkInterface
Local address to bind for outbound connections.- Parameters:
inetSocketAddress- the local address to bind for outbound connections- Returns:
- this bootstrap
-
withMaxInitialLineLength
Sets the maximum HTTP request or status line length in bytes.- Parameters:
maxInitialLineLength- the maximum request or status line length in bytes- Returns:
- this bootstrap
-
withMaxHeaderSize
Sets the maximum HTTP header section size in bytes.- Parameters:
maxHeaderSize- the maximum header section size in bytes- Returns:
- this bootstrap
-
withMaxChunkSize
Largest body piece handed to filters when streaming.- Parameters:
maxChunkSize- the maximum streamed body chunk size in bytes- Returns:
- this bootstrap
-
withAllowRequestToOriginServer
Accept origin-form requests (GET /path) as if the proxy were the origin.- Parameters:
allowRequestToOriginServer- whether to accept origin-form requests- Returns:
- this bootstrap
-
withTlsOrigination
Whether a forward proxy fetches anhttps://URI a client asks for directly, rather than throughCONNECT, by opening TLS to the server itself: an absolute-formGET https://example.com/sent in plain HTTP, an HTTP/2 stream with:scheme httpson anh2cconnection or the proxy's TLS listener, or a secure WebSocket (an absolutewss://URI, or extendedCONNECTwith:scheme https). The server's certificate is checked as an intercepted server's is (theMitmManager's server TLS context, or the JVM's default trust without one), and the connection is pooled, and speaks HTTP/2 (withHttp2Upstream(boolean)) or HTTP/3 (withHttp3Upstream(boolean)), as an intercepted server's would. On by default.Turned off, such requests are refused with
ProxyFailure.BadRequest(400), so that plain-HTTP clients reach TLS servers only through tunnels, which host rules andHttpFilters.proxyToServerAllowMitm()see as such. Anhttps://URI that a filter or script gives a request is fetched over TLS either way, as are requests inside intercepted sessions and a reverse proxy'shttps://upstream: they are the proxy's choice, not the client's.- Parameters:
enabled- whether to originate TLS for clients'https://requests- Returns:
- this bootstrap
-
withProxyAlias
Name used in theViaheader; defaults to the host name.- Parameters:
alias- the name used in Via headers- Returns:
- this bootstrap
-
withAcceptProxyProtocol
Require a PROXY protocol (v1 or v2) header on every inbound connection: the same aswithAcceptProxyProtocol(ProxyProtocolMode)withProxyProtocolMode.REQUIRED, orProxyProtocolMode.OFFforfalse.- Parameters:
acceptProxyProtocol- whether to accept PROXY protocol on client connections- Returns:
- this bootstrap
-
withAcceptProxyProtocol
Whether client connections start with a PROXY protocol header (v1 or v2), read before anything else on the connection (before TLS on a TLS listener, before SOCKS or HTTP/2 detection). The source it names is the client from then on:FlowContext.getClientAddress(),ClientDetails, access logs (%DOWNSTREAM_REMOTE_ADDRESS%) and the header sent on withwithSendProxyProtocol(boolean). Once a connection's first byte has come, the rest of a header must arrive within 5 seconds (or the idle timeout, if shorter), or the connection is closed.ProxyProtocolMode.OPTIONALlets any client that can reach the listener claim any source address: use it only behind a load balancer on a trusted network, ideally withwithProxyProtocolTrustedSources(java.lang.String...)naming the load balancers.- Parameters:
mode-ProxyProtocolMode.OFF(the default),ProxyProtocolMode.REQUIREDorProxyProtocolMode.OPTIONAL- Returns:
- this bootstrap
-
withProxyProtocolTrustedSources
The peers whose PROXY protocol headers are honored, as IP addresses or CIDR ranges (10.0.0.0/8,192.0.2.10,fd00::/8): the load balancers in front of the proxy. A connection from another peer that starts with a PROXY header is closed, whichever the mode; withProxyProtocolMode.REQUIREDevery connection from another peer is closed, and withProxyProtocolMode.OPTIONALone without a header is served as it came. None (the default) honors headers from every peer.- Parameters:
sources- IP addresses or CIDR ranges; none to trust every peer- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if an entry is not an IP literal or a CIDR range
-
withSendProxyProtocol
Send a PROXY protocol v1 header to the final server: first on a direct connection, or through the tunnel once an HTTP chained proxy has accepted the CONNECT. It is not sent where there is no tunnel to the final server: through SOCKS chained proxies, or with plain requests forwarded to an HTTP chained proxy. Server connections that carry the header belong to one client, so the shared server connection pool is not used while this is on.- Parameters:
sendProxyProtocol- whether to send PROXY protocol to upstream servers- Returns:
- this bootstrap
-
withAllowChunkedLength
Accept HTTP/1.1 requests that carry bothTransfer-EncodingandContent-Length, as RFC 9112 section 6.1 allows a server to: theContent-Lengthis removed, the body is read by its chunked coding alone, and the client connection is closed after the response, so that whatever follows the body is never read as another request. Only a sound transfer coding qualifies:chunkedexactly once, as the final coding, with aContent-Lengththat is valid on its own, on a request that is neither aCONNECTnor anUpgrade. Anything else, and every such request from an HTTP/1.0 client, is still answered400. Accepted requests are flagged:FlowContext.isChunkedWithContentLength(),%MP_CHUNKED_LENGTH%in access logs, and thedownstream_rq_chunked_lengthcounter.Off by default, with LittleProxy compatibility too (LittleProxy answers such requests
400): a request with both framings is the classic request smuggling vector, and rejecting it is the safe answer. Turn it on only for clients known to send such requests. HTTP/1's own policy can decide too (Http1PolicyBuilder.allowChunkedLength(boolean)), and wins over this.- Parameters:
allow- whether to accept requests with bothTransfer-EncodingandContent-Length- Returns:
- this bootstrap
-
withMaxWebSocketFrameBufferSize
Largest WebSocket frame payload buffered forHttpFilters.webSocketFrameReceived(org.microproxy.http.WebSocketFrame, boolean); larger frames are streamed and reported as truncated. Default 1 MiB.- Parameters:
maxBytes- the maximum buffered WebSocket frame size in bytes- Returns:
- this bootstrap
-
withMaxWebSocketMessageSize
Largest WebSocket message, in bytes, that the proxy joins from its frames forHttpFilters.filterWebSocketMessage(org.microproxy.http.WebSocketMessage, boolean)or inflates (permessage-deflate) for the frame and message hooks. A larger message, or one that inflates past it (a decompression bomb), fails the connection with close code 1009. Default 16 MiB.- Parameters:
maxBytes- the maximum message size in bytes- Returns:
- this bootstrap
-
withServerConnectionPoolType
Selects the shared upstream connection pool implementation.- Parameters:
poolType- the shared connection pool implementation- Returns:
- this bootstrap
-
withMaxConnectionsPerHost
Pooled connections per target (host:port); default 10.- Parameters:
maxConnectionsPerHost- the maximum pooled connections per destination- Returns:
- this bootstrap
-
withMaxConnections
Pooled connections in total; default 200. When the limit is reached, requests wait up to the connect timeout for a connection and then get503.- Parameters:
maxConnections- the maximum pooled connections across destinations- Returns:
- this bootstrap
-
withPoolIdleTimeout
Closes pooled connections idle for longer than this;nullkeeps them.- Parameters:
idleTimeout- the maximum idle time before a pooled connection is closed- Returns:
- this bootstrap
-
withPoolPerRequestInMitm
WithwithPoolSharedMitmConnections(boolean), leases the server connection per intercepted request rather than per session.- Parameters:
poolPerRequestInMitm- whether intercepted requests lease upstream connections individually- Returns:
- this bootstrap
-
withUseDnsSec
Resolves server names with the validating DNSSEC resolver (DnssecHostResolver) instead of the system resolver.- Parameters:
useDnsSec- whether to validate DNSSEC locally- Returns:
- this bootstrap
-
withDrainTime
How long exchanges in progress may take to finish when the proxy stops, and how long a drain lasts when the admin's/drain_listeners?gracefulstarts one (default 10 seconds, Envoy's--drain-time-s).- Parameters:
drainTime- the drain time, not negative- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if it is negative
-
withDrainStrategy
How a draining proxy tells clients to go elsewhere (defaultDrainStrategy.GRADUAL, as Envoy's--drain-strategy); seeHttpProxyServer.drain(java.time.Duration).- Parameters:
strategy- the strategy- Returns:
- this bootstrap
-
withHealthCheckPath
Answers health checks on the proxy's own listener, as Envoy's health check filter does: a request forpath(its path without the query, exactly) gets200 OKfrom the proxy, or503withx-envoy-immediate-health-check-fail: truewhile the health check fails or the proxy is draining. WithpassThrough, a healthy proxy forwards the request to its server instead (in reverse mode, the upstream's own health); only the failures are answered by the proxy. Null turns it off (the default).- Parameters:
path- the path, starting with/, or null for nonepassThrough- whether a healthy proxy forwards the request- Returns:
- this bootstrap
- Throws:
IllegalArgumentException- if the path does not start with/
-
withAdmin
Serves Envoy's admin API on its own HTTP listener ataddress, apart from the proxy's listeners:/stats,/stats/prometheus,/ready,/server_info,/listeners,/clusters,/config_dump,/logging, and, withPOST,/healthcheck/fail,/healthcheck/ok,/drain_listenersand/quitquitquit;/lists them. Bind it to a loopback address (as--admin-portdoes) unlessa tokenguards it: it can stop the proxy. It turns metrics on. Null (the default) means no admin listener.- Parameters:
address- the address to listen on (port 0 for any free port), or null for none- Returns:
- this bootstrap
-
withAdminToken
Requirestokenon every admin request but/ready: as a bearer token (Authorization: Bearer <token>), or as the password of basic authentication with any user name (or asuser:passworditself, when the token has a colon). Null (the default) requires nothing.- Parameters:
token- the token, or null for none- Returns:
- this bootstrap
-
withCommandLineOptions
The command line the proxy was started with, which the admin's/server_infoshows (secret values redacted) as Envoy shows its own; the launcher passes its arguments.- Parameters:
options- the arguments- Returns:
- this bootstrap
-
start
HttpProxyServer start()Starts the proxy with this configuration.- Returns:
- the running proxy server
-