Interface ContentView


public interface ContentView
Turns a message body into readable text: protobuf as YAML with field numbers, gRPC message by message, msgpack, form data, GraphQL, and so on. The idea follows mitmproxy's content views: a view has a name, says how well it suits some data (priority(byte[], org.microproxy.contentviews.ContentView.Metadata)), and renders it. ContentViews holds a set of views and picks the best one for each body.

Views see bodies with their Content-Encoding already removed. They must be safe to call from many threads at once, and must not throw anything but DecodeException for data they cannot render.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    What a view knows about a body besides its bytes.
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    matches(byte[] data, ContentView.Metadata metadata)
    Whether this view applies to data at all.
    Returns the view's name, in lower case, such as grpc.
    double
    priority(byte[] data, ContentView.Metadata metadata)
    How well this view suits data: 0 (or less) when it does not apply, more for a better fit.
    render(byte[] data, ContentView.Metadata metadata)
    Renders data as text.
  • Method Details

    • name

      String name()
      Returns the view's name, in lower case, such as grpc.
      Returns:
      the view's name, in lower case, such as grpc
    • priority

      double priority(byte[] data, ContentView.Metadata metadata)
      How well this view suits data: 0 (or less) when it does not apply, more for a better fit. Views for a specific Content-Type return 1; more specific views (GraphQL among JSON bodies) return more. In auto mode, the view with the highest priority renders the body.
      Parameters:
      data - the body, decoded
      metadata - what is known about the message
      Returns:
      the priority
    • matches

      default boolean matches(byte[] data, ContentView.Metadata metadata)
      Whether this view applies to data at all.
      Parameters:
      data - the body, decoded
      metadata - what is known about the message
      Returns:
      whether priority(byte[], org.microproxy.contentviews.ContentView.Metadata) is positive
    • render

      String render(byte[] data, ContentView.Metadata metadata) throws DecodeException
      Renders data as text.
      Parameters:
      data - the body, decoded
      metadata - what is known about the message
      Returns:
      the text, usually ending with a newline
      Throws:
      DecodeException - if the data is not what this view renders