Documentation
¶
Overview ¶
Package contentviews formats message bodies for display and interactive editing. Views must support concurrent calls and must not modify their input or metadata.
Index ¶
- Variables
- type CSS
- type DNS
- type GRPC
- type GraphQL
- type HTTP3Frames
- type HexDump
- type HexStream
- type Image
- type InteractiveView
- type JSON
- type JavaScript
- type LimitError
- type MQTT
- type Metadata
- type MsgPack
- type Multipart
- type Protobuf
- type Query
- type Raw
- type Registry
- type Result
- type SocketIO
- type URLEncoded
- type View
- type WBXML
- type XMLHTML
- type ZIP
Constants ¶
This section is empty.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is used by PrettifyMessage when no registry is specified.
var ErrNoView = errors.New("at least one view needs to have a working render priority")
ErrNoView indicates that no registered view has a working render priority.
var ErrUnsupportedMessage = errors.New("unsupported contentview message")
ErrUnsupportedMessage indicates a message type not supported by PrettifyMessage.
Functions ¶
This section is empty.
Types ¶
type CSS ¶
type CSS struct{}
CSS reformats a style sheet's whitespace, as upstream's pure-Python CSS prettifier does: it works with any input and modifies whitespace only.
func (CSS) Name ¶
Name returns the registered view name. The upstream class is named ViewCSS and inherits the name derived from the class name, so that spelling is the registered name.
func (CSS) Prettify ¶
Prettify beautifies the style sheet: rules and declarations get their own lines and indentation while quoted strings and comments stay untouched. Undecodable bytes pass through unchanged. A pattern the engine abandons at the match timeout leaves its area unmarked or its rewrite unapplied, and one warning goes to the package logger.
func (CSS) RenderPriority ¶
RenderPriority prefers nonempty text/css bodies.
func (CSS) SyntaxHighlight ¶
SyntaxHighlight returns the view's highlighting language.
type DNS ¶
type DNS struct{}
DNS renders DNS messages as editable YAML, including TCP framing when metadata carries a TCP or HTTP message. Calls are pure and safe to run concurrently.
func (DNS) Prettify ¶
Prettify decodes DNS wire bytes and returns upstream-ordered YAML. Malformed DNS or missing TCP framing returns an error.
func (DNS) Reencode ¶
Reencode reconstructs DNS wire bytes from YAML without changing metadata. YAML text is bounded at 1 MiB, nesting at 64, and alias expansion at 10,000; malformed fields, excessive decoding work or oversized DNS returns an error.
func (DNS) RenderPriority ¶
RenderPriority prefers DNS media types and flows whose server port is 53 or 5353.
func (DNS) SyntaxHighlight ¶
SyntaxHighlight returns the upstream DNS view's highlighting language.
type GRPC ¶
type GRPC struct{}
GRPC renders length-prefixed gRPC messages as YAML documents, one protobuf message each, and encodes edited documents as uncompressed messages.
func (GRPC) Prettify ¶
Prettify renders every message or fails without partial output. When the matched definition does not fit, the whole body is rendered again without it on the same budget.
func (GRPC) RenderPriority ¶
RenderPriority selects the view for gRPC media types.
func (GRPC) SyntaxHighlight ¶
SyntaxHighlight returns the language of the rendered text.
type GraphQL ¶
type GraphQL struct{}
GraphQL separates GraphQL queries from their JSON envelope.
func (GraphQL) RenderPriority ¶
RenderPriority selects GraphQL JSON objects and batches.
func (GraphQL) SyntaxHighlight ¶
SyntaxHighlight returns the renderer's syntax name.
type HTTP3Frames ¶
type HTTP3Frames struct{}
HTTP3Frames displays HTTP/3 stream frames without changing endpoint state.
func (HTTP3Frames) Prettify ¶
func (HTTP3Frames) Prettify(data []byte, metadata Metadata) (string, error)
Prettify replays an immutable message prefix and attributes completed frames to the message that supplied the final bytes. Calls retain no flow pointers.
func (HTTP3Frames) RenderPriority ¶
func (HTTP3Frames) RenderPriority(_ []byte, metadata Metadata) float64
RenderPriority selects TCP streams carrying an HTTP/3 ALPN.
func (HTTP3Frames) SyntaxHighlight ¶
func (HTTP3Frames) SyntaxHighlight() string
SyntaxHighlight returns the renderer's syntax name.
type HexDump ¶
type HexDump struct{}
HexDump renders sixteen bytes per line, with offsets and an ASCII column.
func (HexDump) RenderPriority ¶
RenderPriority prefers binary data over the raw text view.
func (HexDump) SyntaxHighlight ¶
SyntaxHighlight disables syntax highlighting.
type HexStream ¶
type HexStream struct{}
HexStream renders contiguous lowercase hex and accepts edited hexadecimal.
func (HexStream) Reencode ¶
Reencode accepts either letter case and trailing carriage returns/newlines. It returns an error for odd-length input or any non-hexadecimal character.
func (HexStream) RenderPriority ¶
RenderPriority prefers binary data, below the grouped hex dump view.
func (HexStream) SyntaxHighlight ¶
SyntaxHighlight disables syntax highlighting.
type Image ¶
type Image struct{}
Image displays an image's metadata as YAML under a heading that names the detected format.
func (Image) Prettify ¶
Prettify names the detected image format and lists the metadata of a PNG, GIF, JPEG or ICO image. It returns an error when such an image is malformed; a format it detects but cannot parse gets the heading alone.
func (Image) RenderPriority ¶
RenderPriority prefers image content types other than SVG.
func (Image) SyntaxHighlight ¶
SyntaxHighlight returns the view's highlighting language.
type InteractiveView ¶
type InteractiveView interface {
View
Reencode(prettified string, metadata Metadata) ([]byte, error)
}
InteractiveView also encodes edited text into the original data format.
type JSON ¶
type JSON struct{}
JSON formats JSON with four-space indentation and Python's scalar semantics. Objects retain insertion order, including the position of duplicate names. Lone surrogates are preserved as WTF-8, since Go strings can hold their bytes. Input nesting is limited to 1024 containers.
func (JSON) Prettify ¶
Prettify decodes JSON and formats it as Python's json.dumps with indent=4. Invalid encodings, malformed JSON and excessive nesting return an error.
func (JSON) RenderPriority ¶
RenderPriority prefers nonempty JSON media types.
func (JSON) SyntaxHighlight ¶
SyntaxHighlight returns the upstream JSON view's highlighting language.
type JavaScript ¶
type JavaScript struct{}
JavaScript reformats a script's braces, semicolons and indentation, as upstream's beautifier does, while regular-expression literals, strings, template literals, comments and for-loop heads stay untouched.
func (JavaScript) Prettify ¶
func (JavaScript) Prettify(data []byte, metadata Metadata) (string, error)
Prettify beautifies the script: blocks get their own lines and two-space indentation while the protected areas keep their text. Bytes that are not valid UTF-8 become replacement characters, as Python's replace error handler has it. A pattern the engine abandons at the match timeout leaves its area unmarked or its rewrite unapplied, and one warning goes to the package logger.
func (JavaScript) RenderPriority ¶
func (JavaScript) RenderPriority(data []byte, metadata Metadata) float64
RenderPriority prefers nonempty bodies with a JavaScript content type.
func (JavaScript) SyntaxHighlight ¶
func (JavaScript) SyntaxHighlight() string
SyntaxHighlight returns the view's highlighting language.
type LimitError ¶
LimitError identifies a contentview resource refusal without including input.
func (*LimitError) Error ¶
func (e *LimitError) Error() string
Error reports the view, stage and exhausted resource.
type MQTT ¶
type MQTT struct{}
MQTT renders the supported MQTT control packet summaries.
func (MQTT) RenderPriority ¶
RenderPriority keeps MQTT an explicitly selected display view.
func (MQTT) SyntaxHighlight ¶
SyntaxHighlight returns the renderer's syntax name.
type Metadata ¶
type Metadata struct {
Flow flow.Flow
ContentType string
HTTPMessage *httpmsg.Message
HTTPRequest *httpmsg.Request
TCPMessage *tcp.Message
UDPMessage *udp.Message
WebSocketMessage *websocket.Message
DNSMessage *dns.Message
Protocol string
ProtobufDefinitions string
OriginalData []byte
}
Metadata describes the data being displayed. Every field is optional. The message and flow pointers are borrowed; callers synchronise their access.
type MsgPack ¶
type MsgPack struct{}
MsgPack renders MessagePack data as YAML and encodes edited YAML back.
The YAML representation follows the Rust view: scalars are resolved with the YAML 1.2 core rules, strings that would read back as another type are single-quoted, and map entries keep their wire order. MessagePack binary values, which the Rust view cannot display, use the standard !!binary tag so that they survive an edit as binary rather than becoming strings.
func (MsgPack) RenderPriority ¶
RenderPriority selects the view for MessagePack media types.
func (MsgPack) SyntaxHighlight ¶
SyntaxHighlight returns the language of the rendered text.
type Multipart ¶
type Multipart struct{}
Multipart displays a multipart/form-data body as an ordered YAML mapping.
func (Multipart) Prettify ¶
Prettify decodes the parts named by the message's Content-Type boundary, escapes their bytes, and merges repeated names. It returns an error when metadata has no HTTP message, that message has no Content-Type header, or a part has no end of headers.
func (Multipart) RenderPriority ¶
RenderPriority prefers nonempty multipart/form-data bodies.
func (Multipart) SyntaxHighlight ¶
SyntaxHighlight returns the view's highlighting language.
type Protobuf ¶
type Protobuf struct{}
Protobuf renders protobuf messages as editable YAML. Without definitions, fields are keyed by number and their types are inferred from the wire data; with the protobuf_definitions option, the message matching the request path names known fields.
Numeric alternatives are inline comments on the YAML nodes rather than a textual rewrite of the rendered YAML, so string values that resemble tags are never changed.
func (Protobuf) Prettify ¶
Prettify renders one message, retrying without definitions when the matched definition does not fit the wire data.
func (Protobuf) RenderPriority ¶
RenderPriority selects the view for protobuf media types.
func (Protobuf) SyntaxHighlight ¶
SyntaxHighlight returns the language of the rendered text.
type Query ¶
type Query struct{}
Query displays an HTTP request's query parameters as an ordered YAML mapping.
func (Query) Prettify ¶
Prettify renders query parameters, preserving key order and repeated values. It returns an error when metadata has no HTTP request or YAML encoding fails.
func (Query) RenderPriority ¶
RenderPriority prefers request query parameters when the body is empty.
func (Query) SyntaxHighlight ¶
SyntaxHighlight returns the view's highlighting language.
type Raw ¶
type Raw struct{}
Raw displays UTF-8 text, replacing invalid bytes with backslash escapes.
func (Raw) RenderPriority ¶
RenderPriority supplies the default text fallback priority.
func (Raw) SyntaxHighlight ¶
SyntaxHighlight disables syntax highlighting.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds named views in registration order. Its zero value is empty. Operations are concurrency-safe; view and subscriber calls run without its lock.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry returns a registry containing the built-in views.
func (*Registry) AvailableViews ¶
AvailableViews lists auto followed by the sorted lower-case view names.
func (*Registry) GetView ¶
GetView selects name or, for auto, an empty name, or an unknown name, the highest-priority view. Ties retain registration order. Panicking priority implementations are logged and skipped. ErrNoView means none succeeded.
type Result ¶
type Result struct {
Text string
SyntaxHighlight string
ViewName string
Description string
Truncated bool
// Err records a message-type, view-selection, or rendering failure, even
// when Text contains a successful Raw fallback. Missing content is not an error.
Err error
}
Result contains display text, the selected view, and content-decoding information. An empty ViewName means no view could be selected. Truncated reports line cutoff.
func PrettifyMessage ¶
func PrettifyMessage(message any, f flow.Flow, viewName string, registry *Registry, lineCutoff int) Result
PrettifyMessage renders an HTTP, TCP, UDP, or WebSocket message. HTTP inputs may be *httpmsg.Message, *httpmsg.Request, or *httpmsg.Response. A nil registry uses DefaultRegistry. An empty viewName means auto. Positive lineCutoff limits text through that many newlines; nonpositive values leave the text uncut. Callers pass options.Manager.Int("content_view_lines_cutoff") when appropriate. A failed automatic view falls back to Raw; an explicitly requested view's failure is displayed as an error. Result.Err preserves either failure and wraps ErrUnsupportedMessage for unsupported message types. The input and its flow must not be mutated concurrently while this function runs.
func PrettifyMessageWithMetadata ¶
func PrettifyMessageWithMetadata(message any, metadata Metadata, viewName string, registry *Registry, lineCutoff int) Result
PrettifyMessageWithMetadata renders a message using the same options and fallback behavior as PrettifyMessage. It retains the supplied flow and expands the protobuf definitions home path, deriving other metadata from the message. It does not mutate the supplied metadata. The message and its flow must not be mutated concurrently while this function runs.
type SocketIO ¶
type SocketIO struct{}
SocketIO displays Engine.IO and Socket.IO packet names and payloads.
func (SocketIO) RenderPriority ¶
RenderPriority selects nonempty Socket.IO WebSocket messages.
func (SocketIO) SyntaxHighlight ¶
SyntaxHighlight returns the renderer's syntax name.
type URLEncoded ¶
type URLEncoded struct{}
URLEncoded displays form fields as an ordered YAML mapping.
func (URLEncoded) Prettify ¶
func (URLEncoded) Prettify(data []byte, _ Metadata) (string, error)
Prettify decodes form fields, escapes their bytes, and merges repeated keys. It returns an error if the YAML encoder cannot represent the result.
func (URLEncoded) RenderPriority ¶
func (URLEncoded) RenderPriority(data []byte, metadata Metadata) float64
RenderPriority prefers nonempty URL-encoded form bodies.
func (URLEncoded) SyntaxHighlight ¶
func (URLEncoded) SyntaxHighlight() string
SyntaxHighlight returns the view's highlighting language.
type View ¶
type View interface {
Name() string
SyntaxHighlight() string
Prettify(data []byte, metadata Metadata) (string, error)
RenderPriority(data []byte, metadata Metadata) float64
}
View transforms bytes into human-readable text. SyntaxHighlight returns css, javascript, xml, yaml, none, or error. RenderPriority selects the automatic view: higher wins, negative means unsupported. Prettify returns an error when the data cannot be rendered by this view.
type WBXML ¶
type WBXML struct{}
WBXML renders the pinned ActiveSync WBXML vocabulary as XML.
func (WBXML) Prettify ¶
Prettify parses complete tokens with bounded work and finite truncation errors.
func (WBXML) RenderPriority ¶
RenderPriority selects supported nonempty WBXML media types.
func (WBXML) SyntaxHighlight ¶
SyntaxHighlight returns the renderer's syntax name.
type XMLHTML ¶
type XMLHTML struct{}
XMLHTML formats XML or HTML by changing whitespace only, even in malformed input.
func (XMLHTML) Prettify ¶
Prettify indents markup without repairing it or changing its tags. HTTP metadata supplies decoded text when available. It never returns an error.
func (XMLHTML) RenderPriority ¶
RenderPriority prefers XML and HTML content types, then XML-looking bytes.
func (XMLHTML) SyntaxHighlight ¶
SyntaxHighlight returns the view's highlighting language.
type ZIP ¶
type ZIP struct{}
ZIP displays archive filenames without opening or extracting entries.
func (ZIP) RenderPriority ¶
RenderPriority selects nonempty ZIP media types.
func (ZIP) SyntaxHighlight ¶
SyntaxHighlight returns the renderer's syntax name.
Source Files
¶
- api.go
- backtrack.go
- css.go
- dns.go
- escaped.go
- graphql.go
- grpc.go
- hex.go
- http3.go
- image.go
- javascript.go
- json.go
- message.go
- mqtt.go
- msgpack.go
- msgpack_codec.go
- multipart.go
- protobuf.go
- protobuf_reencode.go
- protobuf_schema.go
- protobuf_wire.go
- query.go
- raw.go
- registry.go
- socketio.go
- urlencoded.go
- wbxml.go
- wbxml_tables.go
- xml_html.go
- yaml.go
- yaml_bounded.go
- zip.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package highlight supplies syntax-token adapters for content presentation.
|
Package highlight supplies syntax-token adapters for content presentation. |
|
Package imagemeta extracts the display metadata of PNG, GIF, JPEG and ICO images, reading exactly the fields mitmproxy's parsers read.
|
Package imagemeta extracts the display metadata of PNG, GIF, JPEG and ICO images, reading exactly the fields mitmproxy's parsers read. |