Class ScriptHeaders

java.lang.Object
org.microproxy.starlark.ScriptHeaders
All Implemented Interfaces:
Iterable<String>, org.microproxy.thirdparty.starlark.eval.StarlarkIndexable, org.microproxy.thirdparty.starlark.eval.StarlarkIterable<String>, org.microproxy.thirdparty.starlark.eval.StarlarkMembershipTestable, org.microproxy.thirdparty.starlark.eval.StarlarkSetIndexable, org.microproxy.thirdparty.starlark.eval.StarlarkValue

public final class ScriptHeaders extends Object implements org.microproxy.thirdparty.starlark.eval.StarlarkSetIndexable, org.microproxy.thirdparty.starlark.eval.StarlarkIterable<String>
The headers of a request or response, or the header block of an HTTP/2 or HTTP/3 frame. Names are case-insensitive; h[name] is the first value (an error if absent), h[name] = v replaces all values, name in h tests presence and iterating yields the distinct names. A frame's header block includes its pseudo-headers (:method, :status, ...).
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.microproxy.thirdparty.starlark.eval.StarlarkSetIndexable

    org.microproxy.thirdparty.starlark.eval.StarlarkSetIndexable.Threaded
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String name, Object value)
    Appends values to a header without removing existing values.
    boolean
    containsKey(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics, Object key)
    Returns whether the key is in the object.
    get(String name, Object defaultValue)
    Returns the first value of a header, with a caller-supplied fallback.
    org.microproxy.thirdparty.starlark.eval.StarlarkList<String>
    getAll(String name)
    Returns every value of a header.
    static org.microproxy.thirdparty.starlark.syntax.TypeConstructor
    Types the builtins that return this class (see ScriptType).
    getIndex(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics, Object key)
    Returns the value associated with the given key.
    org.microproxy.thirdparty.starlark.syntax.StarlarkType
    getStarlarkType(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics)
    Returns the type of this Starlark value, or null if no information is provided.
    boolean
    Reports whether the value is deeply immutable.
    org.microproxy.thirdparty.starlark.eval.StarlarkList<org.microproxy.thirdparty.starlark.eval.Tuple>
    Returns each header value with its name in header order.
     
    org.microproxy.thirdparty.starlark.eval.StarlarkList<String>
    Returns the distinct header names.
    boolean
    remove(String name)
    Removes all values of a header.
    void
    repr(org.microproxy.thirdparty.starlark.eval.Printer printer, org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics)
    Prints an official representation of object x.
    void
    set(String name, Object value)
    Replaces all values of a header.
    void
    setIndex(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics, Object key, Object value)
    Updates an object as if by the Starlark statement object[key] = value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface org.microproxy.thirdparty.starlark.eval.StarlarkValue

    checkHashable, debugPrint, isAcyclic, str, truth
  • Method Details

    • getAssociatedTypeConstructor

      public static org.microproxy.thirdparty.starlark.syntax.TypeConstructor getAssociatedTypeConstructor()
      Types the builtins that return this class (see ScriptType).
      Returns:
      the Starlark type constructor for HTTP headers
    • 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.StarlarkValue
      Returns the type of this Starlark value, or null if no information is provided.

      This method should not be called directly in client code. The canonical way to obtain the type of a value is Starlark.getStarlarkType(java.lang.Object, org.microproxy.thirdparty.starlark.eval.StarlarkSemantics), which injects information obtained in other ways (e.g. from annotations).

      Overrides of this method should not return null: if this method is overridden, it indicates to the machinery processing StarlarkBuiltin annotations that the annotated class doesn't need an auto-generated StarlarkType implementation. Therefore, a null return in an override will cause Starlark.getStarlarkType(java.lang.Object, org.microproxy.thirdparty.starlark.eval.StarlarkSemantics) to fall back to reporting the type as Any.

      Specified by:
      getStarlarkType in interface org.microproxy.thirdparty.starlark.eval.StarlarkValue
      Parameters:
      semantics - the interpreter settings used to determine the type
      Returns:
      the type of this value, or null when no type information is provided
    • getIndex

      public Object getIndex(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics, Object key) throws org.microproxy.thirdparty.starlark.eval.EvalException
      Description copied from interface: org.microproxy.thirdparty.starlark.eval.StarlarkIndexable
      Returns the value associated with the given key.
      Specified by:
      getIndex in interface org.microproxy.thirdparty.starlark.eval.StarlarkIndexable
      Parameters:
      semantics - the interpreter settings used for indexed access
      key - the index or mapping key to look up
      Returns:
      the associated Starlark value
      Throws:
      org.microproxy.thirdparty.starlark.eval.EvalException - if the key is invalid or has no associated value
    • containsKey

      public boolean containsKey(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics, Object key) throws org.microproxy.thirdparty.starlark.eval.EvalException
      Description copied from interface: org.microproxy.thirdparty.starlark.eval.StarlarkMembershipTestable
      Returns whether the key is in the object.
      Specified by:
      containsKey in interface org.microproxy.thirdparty.starlark.eval.StarlarkMembershipTestable
      Parameters:
      semantics - the interpreter settings used for the membership test
      key - the value whose membership is tested
      Returns:
      whether the object contains the key
      Throws:
      org.microproxy.thirdparty.starlark.eval.EvalException - if the key is invalid or membership cannot be evaluated
    • setIndex

      public void setIndex(org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics, Object key, Object value) throws org.microproxy.thirdparty.starlark.eval.EvalException
      Description copied from interface: org.microproxy.thirdparty.starlark.eval.StarlarkSetIndexable
      Updates an object as if by the Starlark statement object[key] = value.
      Specified by:
      setIndex in interface org.microproxy.thirdparty.starlark.eval.StarlarkSetIndexable
      Parameters:
      semantics - the interpreter settings used for indexed assignment
      key - the index or mapping key to update
      value - the new Starlark value to associate with the key
      Throws:
      org.microproxy.thirdparty.starlark.eval.EvalException - if underlying object is immutable.
    • iterator

      public Iterator<String> iterator()
      Specified by:
      iterator in interface Iterable<String>
    • get

      public Object get(String name, Object defaultValue)
      Returns the first value of a header, with a caller-supplied fallback.
      Parameters:
      name - the case-insensitive header name
      defaultValue - the result when the header is absent
      Returns:
      the first header value, or defaultValue
    • getAll

      public org.microproxy.thirdparty.starlark.eval.StarlarkList<String> getAll(String name)
      Returns every value of a header.
      Parameters:
      name - the case-insensitive header name
      Returns:
      an immutable list of values, empty when absent
    • set

      public void set(String name, Object value) throws org.microproxy.thirdparty.starlark.eval.EvalException
      Replaces all values of a header.
      Parameters:
      name - the header name
      value - a string or a list or tuple of strings
      Throws:
      org.microproxy.thirdparty.starlark.eval.EvalException - if headers are read-only or the name or values are invalid
    • add

      public void add(String name, Object value) throws org.microproxy.thirdparty.starlark.eval.EvalException
      Appends values to a header without removing existing values.
      Parameters:
      name - the header name
      value - a string or a list or tuple of strings
      Throws:
      org.microproxy.thirdparty.starlark.eval.EvalException - if headers are read-only or the name or values are invalid
    • remove

      public boolean remove(String name) throws org.microproxy.thirdparty.starlark.eval.EvalException
      Removes all values of a header.
      Parameters:
      name - the case-insensitive header name
      Returns:
      whether any values were removed
      Throws:
      org.microproxy.thirdparty.starlark.eval.EvalException - if headers are read-only
    • keys

      public org.microproxy.thirdparty.starlark.eval.StarlarkList<String> keys()
      Returns the distinct header names.
      Returns:
      an immutable list of header names
    • items

      public org.microproxy.thirdparty.starlark.eval.StarlarkList<org.microproxy.thirdparty.starlark.eval.Tuple> items()
      Returns each header value with its name in header order.
      Returns:
      an immutable list of name/value tuples, including repeated names
    • 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.StarlarkValue
      Prints 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:
      repr in interface org.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
    • isImmutable

      public boolean isImmutable()
      Description copied from interface: org.microproxy.thirdparty.starlark.eval.StarlarkValue
      Reports whether the value is deeply immutable.
      Specified by:
      isImmutable in interface org.microproxy.thirdparty.starlark.eval.StarlarkValue
      Returns:
      whether this value and all values reachable from it are immutable