Package org.microproxy.starlark
Class ScriptContext
java.lang.Object
org.microproxy.starlark.ScriptContext
- All Implemented Interfaces:
org.microproxy.thirdparty.starlark.eval.StarlarkValue,org.microproxy.thirdparty.starlark.eval.Structure
public final class ScriptContext
extends Object
implements org.microproxy.thirdparty.starlark.eval.Structure
Per-request context: who the client is,
vars, a dict that lives as long as the request
so on_request can leave notes for on_response, timings, a snapshot of the
exchange's timings taken when it is read, client_hello, the TLS ClientHello that
started the client's intercepted session (None before it is read, and for plain HTTP),
forwarded_via, the session's server that the request is forwarded through as the
client's proxy (host:port: an intercepted HTTPS proxy, or an HTTP proxy whose session is
plain HTTP), or None, socks_version, the SOCKS version the client reached the
proxy with (5, or 4 for SOCKS4 and 4a), or None for an HTTP client,
transparent_quic, whether the client's QUIC came to the transparent QUIC listener, and
script_stats, what the calls into scripts for the exchange added up to so far (calls,
time, interpreter steps and bytes of values created; see ScriptUsageValue),
early_data, whether the HTTP/3 request arrived as 0-RTT early data, which may be a
replay: a hook may answer it 425 (Too Early) for its client to send again after the
handshake, protocol, the protocol the client speaks to the proxy ("http1",
"http2" or "http3", whose protocol policy applies), or None where the
hook gets no flow. How the exchange is going: failure, why the proxy has to answer it itself (a
Failure, as on_failure gets it) or None, response_flags, the
Envoy-style flags so far as short codes (["UF"]), and response_code_details
("proxy_failure:connect_failed", ...) or None. trace_id and
span_id are the exchange's trace id and the proxy's span id for it, in hex, with a tracer
(microproxy-otel), else None; the trace module adds to that span.-
Method Summary
Modifier and TypeMethodDescriptionstatic org.microproxy.thirdparty.starlark.syntax.TypeConstructorTypes the builtins that return this class (seeScriptType).Returns the error message to print for an attempt to access an undefined field.com.google.common.collect.ImmutableList<String> Returns the names of this value's fields, in some undefined but stable order.org.microproxy.thirdparty.starlark.syntax.StarlarkTypegetStarlarkType(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics) Returns the Starlark type of this struct.Returns the value of the field with the given name, or null if the field does not exist.voidrepr(org.microproxy.thirdparty.starlark.eval.Printer printer, org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics) Prints an official representation of object x.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.microproxy.thirdparty.starlark.eval.StarlarkValue
checkHashable, debugPrint, isAcyclic, isImmutable, str, truthMethods inherited from interface org.microproxy.thirdparty.starlark.eval.Structure
getValue, setField
-
Method Details
-
getAssociatedTypeConstructor
public static org.microproxy.thirdparty.starlark.syntax.TypeConstructor getAssociatedTypeConstructor()Types the builtins that return this class (seeScriptType).- Returns:
- the Starlark type constructor for a context value
-
getStarlarkType
public org.microproxy.thirdparty.starlark.syntax.StarlarkType getStarlarkType(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics) Description copied from interface:org.microproxy.thirdparty.starlark.eval.StructureReturns the Starlark type of this struct. For efficiency, implementations should override this method to return a memoized value.- Specified by:
getStarlarkTypein interfaceorg.microproxy.thirdparty.starlark.eval.StarlarkValue- Specified by:
getStarlarkTypein interfaceorg.microproxy.thirdparty.starlark.eval.Structure- Parameters:
semantics- the interpreter settings used to determine the type- Returns:
- the type of this value, or null when no type information is provided
-
getValue
Description copied from interface:org.microproxy.thirdparty.starlark.eval.StructureReturns the value of the field with the given name, or null if the field does not exist. The interpreter (Starlark code) calls the getValue below, which has access to StarlarkSemantics.The set of names for which
getValuereturns non-null should matchgetFieldNamesif possible.- Specified by:
getValuein interfaceorg.microproxy.thirdparty.starlark.eval.Structure- Parameters:
name- the name of the field to retrieve- Returns:
- the field value, or null if the field does not exist
-
getFieldNames
Description copied from interface:org.microproxy.thirdparty.starlark.eval.StructureReturns the names of this value's fields, in some undefined but stable order.A call to
getValuefor each of these names should return non-null, though this is not enforced.The Starlark expression
dir(x)reports the union ofgetFieldNames()and any StarlarkMethod-annotated fields and methods of this value.- Specified by:
getFieldNamesin interfaceorg.microproxy.thirdparty.starlark.eval.Structure- Returns:
- the field names in a stable order
-
getErrorMessageForUnknownField
Description copied from interface:org.microproxy.thirdparty.starlark.eval.StructureReturns the error message to print for an attempt to access an undefined field.May return null to use a default error message.
- Specified by:
getErrorMessageForUnknownFieldin interfaceorg.microproxy.thirdparty.starlark.eval.Structure- Parameters:
field- the undefined field name- Returns:
- the diagnostic message, or null to use the default
-
repr
public void repr(org.microproxy.thirdparty.starlark.eval.Printer printer, org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics) Description copied from interface:org.microproxy.thirdparty.starlark.eval.StarlarkValuePrints an official representation of object x.Convention is that the string should be parseable back to the value x. If this isn't feasible then it should be a short human-readable description enclosed in angled brackets, e.g.
"<foo object>".- Specified by:
reprin interfaceorg.microproxy.thirdparty.starlark.eval.StarlarkValue- Parameters:
printer- a printer to be used for formatting nested values.semantics- the interpreter settings used to format nested values
-