marbl

package
v3.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

func (df Data) FrameType() FrameType

FrameType returns DataFrame

func (Data) String

func (df Data) String() 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

type Frame interface {
	String() string
	FrameType() FrameType
}

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

func (h *Handler) Write(b []byte) (int, error)

Write writes frames to all websocket subscribers and returns the number of bytes written and an error.

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

func (hf Header) FrameType() FrameType

FrameType returns HeaderFrame

func (Header) String

func (hf Header) String() 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

func NewModifier(w io.Writer) *Modifier

NewModifier returns a marbl.Modifier initialized with a marbl.Stream.

func (*Modifier) ModifyRequest

func (m *Modifier) ModifyRequest(req *http.Request) error

ModifyRequest writes an HTTP request to the log stream.

func (*Modifier) ModifyResponse

func (m *Modifier) ModifyResponse(res *http.Response) error

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

func NewReader(r io.Reader) *Reader

NewReader returns a Reader initialized with a buffered reader.

func (*Reader) ReadFrame

func (r *Reader) ReadFrame() (Frame, error)

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

func NewStream(w io.Writer) *Stream

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

func (s *Stream) Close() error

Close signals Stream to stop listening for frames in the log loop and stop writing logs.

func (*Stream) LogRequest

func (s *Stream) LogRequest(id string, req *http.Request) error

LogRequest writes an http.Request to Stream with an id unique for the request / response pair.

func (*Stream) LogResponse

func (s *Stream) LogResponse(id string, res *http.Response) error

LogResponse writes an http.Response to Stream with an id unique for the request / response pair.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL