Package org.microproxy.contentviews
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 ClassesModifier and TypeInterfaceDescriptionstatic final recordWhat a view knows about a body besides its bytes. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleanmatches(byte[] data, ContentView.Metadata metadata) Whether this view applies todataat all.name()Returns the view's name, in lower case, such asgrpc.doublepriority(byte[] data, ContentView.Metadata metadata) How well this view suitsdata: 0 (or less) when it does not apply, more for a better fit.render(byte[] data, ContentView.Metadata metadata) Rendersdataas text.
-
Method Details
-
name
String name()Returns the view's name, in lower case, such asgrpc.- Returns:
- the view's name, in lower case, such as
grpc
-
priority
How well this view suitsdata: 0 (or less) when it does not apply, more for a better fit. Views for a specificContent-Typereturn 1; more specific views (GraphQL among JSON bodies) return more. Inautomode, the view with the highest priority renders the body.- Parameters:
data- the body, decodedmetadata- what is known about the message- Returns:
- the priority
-
matches
Whether this view applies todataat all.- Parameters:
data- the body, decodedmetadata- what is known about the message- Returns:
- whether
priority(byte[], org.microproxy.contentviews.ContentView.Metadata)is positive
-
render
Rendersdataas text.- Parameters:
data- the body, decodedmetadata- 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
-