Class ScriptedProxy.Builder

java.lang.Object
org.microproxy.starlark.ScriptedProxy.Builder
Enclosing class:
ScriptedProxy

public static final class ScriptedProxy.Builder extends Object
Options for ScriptedProxy.
  • Method Details

    • reload

      public ScriptedProxy.Builder reload(boolean 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

      public ScriptedProxy.Builder maxBodySize(int 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

      public ScriptedProxy.Builder fallback(ChainedProxyManager fallback)
      Routes requests when the script has no upstream function or it returns None; by default such requests connect directly.
      Parameters:
      fallback - the routing manager, or null to connect directly
      Returns:
      this builder
    • constants

      public ScriptedProxy.Builder constants(Map<String,?> 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, and Lists and Maps 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

      public ScriptedProxy.Builder protoSchema(ProtoSchema schema)
      A protobuf schema for the script's protobuf and grpc modules: with it, protobuf.decode(data, type="pkg.Message") keys fields by name and protobuf.encode(fields, type="pkg.Message") takes names.
      Parameters:
      schema - the schema, as from ProtoSchema.load(java.nio.file.Path)
      Returns:
      this builder
    • stats

      public ScriptedProxy.Builder stats(StatsRegistry stats)
      The registry the script's stats module counts into, as script.<name> (ScriptStats); usually the proxy's (HttpProxyServerBootstrap.getStats()). Without one, or with StatsRegistry.NOOP, the script's metrics count nothing.
      Parameters:
      stats - the registry, or null for none
      Returns:
      this builder
    • statsName

      public ScriptedProxy.Builder statsName(String statsName)
      The name the script's hooks.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

      public ScriptedProxy.Builder observer(ScriptCallObserver observer)
      Shows every call into the script to observer: when it starts, and its steps, bytes of values created, time and error when it ends (see ScriptCallObserver).
      Parameters:
      observer - the observer, or null for none
      Returns:
      this builder
    • build

      public ScriptedProxy build() throws IOException, ScriptException
      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 inspected
      ScriptException - if compilation or top-level execution fails