public final class ProxyResult extends Object
A result is exactly one of four kinds:
ProxyResult.Kind.PROXY — a concrete host:port proxy.ProxyResult.Kind.DIRECT — the selected mode genuinely yields DIRECT
(e.g. ProxyMode.DISABLED or a PAC script returning DIRECT).ProxyResult.Kind.ERROR — the selected mode failed; getReason() carries
the technical cause (e.g. pac-url-not-found, pac-download-failed,
pac-evaluation-failed). This is not DIRECT.ProxyResult.Kind.NOT_IMPLEMENTED — the selected mode is reserved/not implemented.| Modifier and Type | Class and Description |
|---|---|
static class |
ProxyResult.Kind
The kind of a
ProxyResult. |
| Modifier and Type | Method and Description |
|---|---|
static ProxyResult |
direct()
Creates a DIRECT result with a generic reason.
|
static ProxyResult |
direct(String reason)
Creates a DIRECT result (no proxy needed).
|
static ProxyResult |
error(String reason)
Creates an ERROR result carrying the technical cause.
|
String |
getHost()
Returns the proxy host, or
null for non-PROXY results. |
ProxyResult.Kind |
getKind()
Returns the
ProxyResult.Kind of this result. |
int |
getPort()
Returns the proxy port, or
0 for non-PROXY results. |
String |
getReason()
Returns a machine-readable diagnostic reason for this result.
|
boolean |
isDirect()
Returns
true only if the mode genuinely yields DIRECT (not on error). |
boolean |
isError()
Returns
true if resolution failed; see getReason(). |
boolean |
isNotImplemented()
Returns
true if the selected mode is reserved/not implemented. |
boolean |
isProxy()
Returns
true for a concrete host:port proxy. |
static ProxyResult |
notImplemented(String reason)
Creates a NOT_IMPLEMENTED result.
|
static ProxyResult |
of(String host,
int port)
Creates a PROXY result with a generic reason.
|
static ProxyResult |
proxy(String host,
int port,
String reason)
Creates a PROXY result.
|
Proxy |
toJavaProxy()
Converts to
Proxy, honouring the ProxyResult.Kind:
ProxyResult.Kind.PROXY → an HTTP Proxy for host:port,
ProxyResult.Kind.DIRECT → Proxy.NO_PROXY,
ProxyResult.Kind.ERROR / ProxyResult.Kind.NOT_IMPLEMENTED → IllegalStateException.
Errors and not-implemented results deliberately throw instead of silently
degrading to Proxy.NO_PROXY, so a failed resolution can never be
mistaken for a genuine DIRECT route. |
Proxy |
toJavaProxyOrNoProxy()
Best-effort variant of
toJavaProxy() that never throws:
ProxyResult.Kind.PROXY → an HTTP Proxy for host:port,
ProxyResult.Kind.DIRECT, ProxyResult.Kind.ERROR, ProxyResult.Kind.NOT_IMPLEMENTED
→ Proxy.NO_PROXY.
Only use this when the caller has explicitly decided that a failed or
not-implemented resolution should fall back to a direct connection. |
String |
toString() |
public static ProxyResult direct(String reason)
public static ProxyResult direct()
public static ProxyResult proxy(String host, int port, String reason)
public static ProxyResult of(String host, int port)
public static ProxyResult error(String reason)
public static ProxyResult notImplemented(String reason)
public ProxyResult.Kind getKind()
ProxyResult.Kind of this result.public boolean isProxy()
true for a concrete host:port proxy.public boolean isDirect()
true only if the mode genuinely yields DIRECT (not on error).public boolean isError()
true if resolution failed; see getReason().public boolean isNotImplemented()
true if the selected mode is reserved/not implemented.public String getHost()
null for non-PROXY results.public int getPort()
0 for non-PROXY results.public String getReason()
public Proxy toJavaProxy()
Proxy, honouring the ProxyResult.Kind:
ProxyResult.Kind.PROXY → an HTTP Proxy for host:port,ProxyResult.Kind.DIRECT → Proxy.NO_PROXY,ProxyResult.Kind.ERROR / ProxyResult.Kind.NOT_IMPLEMENTED → IllegalStateException.Proxy.NO_PROXY, so a failed resolution can never be
mistaken for a genuine DIRECT route. Callers that explicitly want a best-effort
NO_PROXY for those kinds must use toJavaProxyOrNoProxy().IllegalStateException - if this result is an ProxyResult.Kind.ERROR or
ProxyResult.Kind.NOT_IMPLEMENTED.public Proxy toJavaProxyOrNoProxy()
toJavaProxy() that never throws:
ProxyResult.Kind.PROXY → an HTTP Proxy for host:port,ProxyResult.Kind.DIRECT, ProxyResult.Kind.ERROR, ProxyResult.Kind.NOT_IMPLEMENTED
→ Proxy.NO_PROXY.ProxyResult (and toJavaProxy()),
so an ProxyResult.Kind.ERROR is never masked as a successful DIRECT.Copyright © 2026. All rights reserved.