dump

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 22 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

This section is empty.

Types

type BinaryData

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

BinaryData represents binary content as a hex-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"`
	RawBody     string         `json:"rawBody,omitempty"`
	IsBinary    bool           `json:"isBinary"`
}

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).

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.

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) Dump

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

Dump broadcasts a request/response dump 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 serves the HTML page for regular requests and establishes SSE connections for requests with Accept: text/event-stream header.

type ImageData

type ImageData struct {
	BinaryData
}

ImageData represents image content with binary data.

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"`
}

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.

Jump to

Keyboard shortcuts

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