package marbl
import "github.com/google/martian/v3/marbl"
Package marbl provides HTTP traffic logs streamed over websockets that can be added to any point within a Martian modifier tree. Marbl transmits HTTP logs that are serialized based on the following schema:
Frame Header FrameType uint8 MessageType uint8 ID [8]byte Payload HeaderFrame/DataFrame
Header Frame NameLen uint32 ValueLen uint32 Name variable Value variable
Data Frame Index uint32 Terminal uint8 Len uint32 Data variable
Index ¶
- type Data
- type Frame
- type FrameType
- type Handler
- func NewHandler() *Handler
- func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (h *Handler) Write(b []byte) (int, error)
- type Header
- type MessageType
- type Modifier
- func NewModifier(w io.Writer) *Modifier
- func (m *Modifier) ModifyRequest(req *http.Request) error
- func (m *Modifier) ModifyResponse(res *http.Response) error
- type Reader
- type Stream
Types ¶
type Data ¶
type Data struct { ID string MessageType MessageType Index uint32 Terminal bool Data []byte }
Data is the payload (body) of the request or response.
func (Data) FrameType ¶
FrameType returns DataFrame
func (Data) String ¶
String returns the contents of a Data frame in a format appropriate for debugging and runtime logging. The contents of the data content slice (df.Data) is not printed, instead the length of Data is printed.
type Frame ¶
Frame describes the interface for a frame (either Data or Header).
type FrameType ¶
type FrameType uint8
FrameType indicates whether the frame contains a Header or Data.
const ( // UnknownFrame indicates an unknown type of Frame. UnknownFrame FrameType = 0x0 // HeaderFrame indicates a frame that contains a header. HeaderFrame FrameType = 0x1 // DataFrame indicates a frame that contains the payload, usually the body. DataFrame FrameType = 0x2 )
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler exposes marbl logs over websockets.
func NewHandler ¶
func NewHandler() *Handler
NewHandler instantiates a Handler with an empty set of subscriptions.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
func (*Handler) Write ¶
Write writes frames to all websocket subscribers and returns the number of bytes written and an error.
type Header ¶
type Header struct { ID string MessageType MessageType Name string Value string }
Header is either an HTTP header or meta-data pertaining to the request or response.
func (Header) FrameType ¶
FrameType returns HeaderFrame
func (Header) String ¶
String returns the contents of a Header frame in a format appropriate for debugging and runtime logging.
type MessageType ¶
type MessageType uint8
MessageType incicates whether the message represents an HTTP request or response.
const ( // Unknown type of Message. Unknown MessageType = 0x0 // Request indicates a message that contains an HTTP request. Request MessageType = 0x1 // Response indicates a message that contains an HTTP response. Response MessageType = 0x2 )
type Modifier ¶
type Modifier struct {
// contains filtered or unexported fields
}
Modifier implements the Martian modifier interface so that marbl logs can be captured at any point in a Martian modifier tree.
func NewModifier ¶
NewModifier returns a marbl.Modifier initialized with a marbl.Stream.
func (*Modifier) ModifyRequest ¶
ModifyRequest writes an HTTP request to the log stream.
func (*Modifier) ModifyResponse ¶
ModifyResponse writes an HTTP response to the log stream.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps a buffered Reader that reads from the io.Reader and emits Frames.
func NewReader ¶
NewReader returns a Reader initialized with a buffered reader.
func (*Reader) ReadFrame ¶
ReadFrame reads from r, determines the FrameType, and returns either a Header or Data and an error.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream writes logs of requests and responses to a writer.
func NewStream ¶
NewStream initializes a Stream with an io.Writer to log requests and responses to. Upon construction, a goroutine is started that listens for frames and writes them to w.
func (*Stream) Close ¶
Close signals Stream to stop listening for frames in the log loop and stop writing logs.
func (*Stream) LogRequest ¶
LogRequest writes an http.Request to Stream with an id unique for the request / response pair.
func (*Stream) LogResponse ¶
LogResponse writes an http.Response to Stream with an id unique for the request / response pair.
Source Files ¶
handler.go marbl.go modifier.go reader.go
- Version
- v3.2.1
- Published
- May 19, 2021
- Platform
- windows/amd64
- Imports
- 15 packages
- Last checked
- 1 hour ago –
Tools for package owners.