dump

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package dump provides HTTP request/response capturing and display functionality. It includes console output formatting and a web-based inspector interface.

Package dump provides HTTP request/response capturing and display functionality. It includes console output formatting and a web-based inspector interface.

Package dump provides HTTP request/response capturing and display functionality. It includes console output formatting and a web-based inspector interface.

Index

Constants

This section is empty.

Variables

View Source
var IndexHTML string

Functions

func IsSseResponse added in v1.0.1

func IsSseResponse(header http.Header) bool

IsSseResponse checks if response is an SSE stream.

Types

type BinaryData

type BinaryData struct {
	Data string `json:"data"`
}

BinaryData represents binary content as a base64-encoded string.

type ConsoleDumper

type ConsoleDumper struct {
	// contains filtered or unexported fields
}

ConsoleDumper prints HTTP dump information to the console in a formatted table with support for verbose mode and configurable table width.

func NewConsoleDumper

func NewConsoleDumper(opts ...Opts) *ConsoleDumper

NewConsoleDumper creates a new ConsoleDumper with default options (non-verbose mode, 80 character table width).

func (*ConsoleDumper) Dump

func (cd *ConsoleDumper) Dump(d *Dump)

Dump prints the HTTP dump to console

type ConsoleDumperOptions

type ConsoleDumperOptions struct {
	Verbose      bool
	TableWidth   int // Total table width (default: 80)
	MaxBodyWidth int // Maximum width for body content (default: 72)
}

ConsoleDumperOptions defines options for creating a ConsoleDumper.

type Data

type Data struct {
	Headers     http.Header    `json:"headers,omitempty"`
	Cookies     []*http.Cookie `json:"cookies,omitempty"`
	ContentType string         `json:"contentType,omitempty"`
	Body        any            `json:"body,omitempty"`
	IsBinary    bool           `json:"isBinary"`
	RawBody     string         `json:"rawBody,omitempty"`
	PDFPages    int            `json:"pdfPages,omitempty"`
}

Data contains parsed HTTP request or response data including headers, cookies, content type, and body (which may be structured or binary).

type Dump

type Dump struct {
	ID           string        `json:"id"`
	RequestDump  *RequestData  `json:"request"`
	ResponseDump *ResponseData `json:"response"`
	Timestamp    string        `json:"timestamp"`
}

Dump contains a complete captured HTTP transaction including request details, response details, and metadata like ID and timestamp.

func NewDump

func NewDump(req *http.Request, res *http.Response, requestBody []byte, responseBody []byte) (*Dump, error)

NewDump creates a new Dump from HTTP request and response data. It captures headers, cookies, body content, and metadata, then parses the body based on content type (form, multipart, image, PDF, binary, or text). For SSE responses, it parses individual events from the stream.

type HttpDumper

type HttpDumper struct {
	// contains filtered or unexported fields
}

HttpDumper manages Server-Sent Events (SSE) connections for broadcasting request dumps to connected web clients in real-time. It also stores captured dumps in memory for retrieval via API.

func NewHttpDumper

func NewHttpDumper() *HttpDumper

NewHttpDumper creates a new HttpDumper instance that manages SSE connections for real-time request broadcasting to web clients.

func (*HttpDumper) BroadcastSseUpdate added in v1.0.1

func (u *HttpDumper) BroadcastSseUpdate(dumpID string, events []*SseEvent, complete bool)

BroadcastSseUpdate sends an SSE event update to all connected clients.

func (*HttpDumper) Dump

func (u *HttpDumper) Dump(dump *Dump)

Dump stores a request/response dump in memory and broadcasts it to all connected SSE clients.

func (*HttpDumper) Serve

func (u *HttpDumper) Serve(w http.ResponseWriter, r *http.Request)

Serve handles HTTP requests for the web interface. It uses the Accept header and HTTP method to differentiate request purpose:

  • GET with Accept: text/event-stream → SSE connection
  • GET with Accept: application/json → return stored dumps as JSON
  • DELETE → clear all stored dumps
  • GET (default) → serve HTML page

func (*HttpDumper) UpdateDump added in v1.0.1

func (u *HttpDumper) UpdateDump(dump *Dump)

UpdateDump updates an existing dump in memory by ID and broadcasts the update.

type Opts

type Opts func(c *ConsoleDumper)

Opts is a function type for configuring ConsoleDumper instances.

func WithTableWidth

func WithTableWidth(tableWidth int) Opts

WithTableWidth returns an option function that sets the table width.

func WithVerbose

func WithVerbose(verbose bool) Opts

WithVerbose returns an option function that enables or disables verbose output.

type PDFData

type PDFData struct {
	BinaryData
	PDFPages  int    `json:"pdfPages"`
	FirstPage string `json:"-"`
}

PDFData represents PDF content with page count and first page preview.

type RequestData

type RequestData struct {
	Data
	Method string     `json:"method,omitempty"`
	URL    string     `json:"url,omitempty"`
	Path   string     `json:"path,omitempty"`
	Query  url.Values `json:"query,omitempty"`
}

RequestData contains captured HTTP request information including method, URL, path, query parameters, and embedded Data fields.

type ResponseData

type ResponseData struct {
	Data
	StatusCode int         `json:"statusCode"`
	StatusLine string      `json:"statusLine,omitempty"`
	SseEvents  []*SseEvent `json:"sseEvents,omitempty"`
	IsSse      bool        `json:"isSse"`
}

ResponseData contains captured HTTP response information including status code, status line, and embedded Data fields.

type ServerResetEvent

type ServerResetEvent struct {
	Type      string `json:"type"`
	StartTime int64  `json:"startTime"`
}

ServerResetEvent is sent to SSE clients when the server restarts, allowing clients to clear old data and synchronize with the new server instance.

type SseEvent added in v1.0.1

type SseEvent struct {
	ID    string `json:"id,omitempty"`
	Event string `json:"event,omitempty"`
	Data  string `json:"data"`
	Retry int    `json:"retry,omitempty"`
	Index int    `json:"index"`
}

SseEvent represents a single Server-Sent Event.

func ParseSseEventsPartial added in v1.0.1

func ParseSseEventsPartial(data []byte, eventOffset int) []*SseEvent

ParseSseEventsPartial parses SSE events but only returns NEW complete events that weren't included in the previous parse. The eventOffset is the number of complete events already processed, and only events beyond that count are returned.

type SseEventUpdate added in v1.0.1

type SseEventUpdate struct {
	DumpID    string      `json:"dumpId"`
	Events    []*SseEvent `json:"events"`
	Timestamp string      `json:"timestamp"`
	Complete  bool        `json:"complete"`
}

SseEventUpdate represents a partial dump update with new SSE events.

Jump to

Keyboard shortcuts

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