Package org.microproxy.starlark
Class ScriptedProxy.Builder
java.lang.Object
org.microproxy.starlark.ScriptedProxy.Builder
- Enclosing class:
ScriptedProxy
Options for
ScriptedProxy.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Compiles the script and runs its top level.Adds read-only globals the script can use, such as tokens or host lists that should not be written into the script.fallback(ChainedProxyManager fallback) Routes requests when the script has noupstreamfunction or it returnsNone; by default such requests connect directly.limits(StarlarkScript.Limits limits) Step and time limits for each hook call.maxBodySize(int maxBodySize) The most body bytes buffered for a script (default 10 MiB).observer(ScriptCallObserver observer) Shows every call into the script toobserver: when it starts, and its steps, bytes of values created, time and error when it ends (seeScriptCallObserver).protoSchema(ProtoSchema schema) A protobuf schema for the script'sprotobufandgrpcmodules: with it,protobuf.decode(data, type="pkg.Message")keys fields by name andprotobuf.encode(fields, type="pkg.Message")takes names.reload(boolean reload) Re-read the file when it changes (default true).stats(StatsRegistry stats) The registry the script'sstatsmodule counts into, asscript.<name>(ScriptStats); usually the proxy's (HttpProxyServerBootstrap.getStats()).The name the script'shooks.starlark.*stats are tagged with (microproxy_script); by default its file name without.star.
-
Method Details
-
reload
Re-read the file when it changes (default true).- Parameters:
reload- whether to check for file changes; ignored for source strings- Returns:
- this builder
-
limits
Step and time limits for each hook call.- Parameters:
limits- the execution bounds for loading and calling the script- Returns:
- this builder
-
maxBodySize
The most body bytes buffered for a script (default 10 MiB).- Parameters:
maxBodySize- the positive buffer limit in bytes- Returns:
- this builder
- Throws:
IllegalArgumentException- if the limit is not positive
-
fallback
Routes requests when the script has noupstreamfunction or it returnsNone; by default such requests connect directly.- Parameters:
fallback- the routing manager, or null to connect directly- Returns:
- this builder
-
constants
Adds read-only globals the script can use, such as tokens or host lists that should not be written into the script. Values are strings, ints (Integer,Long,BigInteger, ...), booleans, andLists andMaps of them (map keys: strings, ints or booleans); they are copied and frozen. They are predeclared, so the type checker knows their types, and the script cannot assign them. Later calls add to earlier ones.- Parameters:
constants- the additional globals, merged with earlier calls- Returns:
- this builder
- Throws:
IllegalArgumentException- for a name that is not an identifier or would hide a built-in (len,json,Request, ...), or a value of another type
-
protoSchema
A protobuf schema for the script'sprotobufandgrpcmodules: with it,protobuf.decode(data, type="pkg.Message")keys fields by name andprotobuf.encode(fields, type="pkg.Message")takes names.- Parameters:
schema- the schema, as fromProtoSchema.load(java.nio.file.Path)- Returns:
- this builder
-
stats
The registry the script'sstatsmodule counts into, asscript.<name>(ScriptStats); usually the proxy's (HttpProxyServerBootstrap.getStats()). Without one, or withStatsRegistry.NOOP, the script's metrics count nothing.- Parameters:
stats- the registry, or null for none- Returns:
- this builder
-
statsName
The name the script'shooks.starlark.*stats are tagged with (microproxy_script); by default its file name without.star.- Parameters:
statsName- the name, or null for the default- Returns:
- this builder
-
observer
Shows every call into the script toobserver: when it starts, and its steps, bytes of values created, time and error when it ends (seeScriptCallObserver).- Parameters:
observer- the observer, or null for none- Returns:
- this builder
-
build
Compiles the script and runs its top level.- Returns:
- a proxy using the compiled script
- Throws:
IOException- if the script file cannot be read or inspectedScriptException- if compilation or top-level execution fails
-