har

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package har records bounded HTTP Archive (HAR) 1.2 exchanges.

Index

Constants

View Source
const (
	Version            = "1.2"
	BodyOmittedComment = "Body omitted by fetch because it exceeds the 16 MiB HAR capture limit"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	Size     int64  `json:"size"`
	MIMEType string `json:"mimeType"`
	Text     string `json:"text,omitempty"`
	Encoding string `json:"encoding,omitempty"`
	Comment  string `json:"comment,omitempty"`
}
type Cookie struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Path     string `json:"path,omitempty"`
	Domain   string `json:"domain,omitempty"`
	Expires  string `json:"expires,omitempty"`
	HttpOnly bool   `json:"httpOnly,omitzero"`
	Secure   bool   `json:"secure,omitzero"`
}

type Creator

type Creator struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type Entry

type Entry struct {
	StartedDateTime string         `json:"startedDateTime"`
	Time            float64        `json:"time"`
	Request         Request        `json:"request"`
	Response        Response       `json:"response"`
	Cache           map[string]any `json:"cache"`
	Timings         TimingsHAR     `json:"timings"`
	ServerIPAddress string         `json:"serverIPAddress,omitempty"`
}

type NameValue

type NameValue struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type PostData

type PostData struct {
	MIMEType string `json:"mimeType"`
	Text     string `json:"text,omitempty"`
	Encoding string `json:"encoding,omitempty"`
	Comment  string `json:"comment,omitempty"`
}

type Recorder

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

Recorder reserves a HAR destination and records one final exchange. Recorder is safe for the request observer and response tee to use from different goroutines, although a fetch invocation normally has one stream.

func New

func New(path string, clobber bool) (*Recorder, error)

New reserves path before a request starts. It does not create the final destination until Finalize commits a complete HAR document.

func (*Recorder) CaptureResponse

func (r *Recorder) CaptureResponse(resp *http.Response) *ResponseCapture

CaptureResponse creates the bounded tee for resp's decoded response body.

func (*Recorder) Close

func (r *Recorder) Close() error

Close removes an uncommitted reservation. It is safe to call after Finalize and should normally be deferred by the caller.

func (*Recorder) Finalize

func (r *Recorder) Finalize(resp *http.Response, response *ResponseCapture, timings Timings) error

Finalize writes and atomically commits the one-entry HAR document. The response body must have been consumed as far as the caller intends before this method is called.

func (*Recorder) ObserveRequest

func (r *Recorder) ObserveRequest(req *http.Request)

ObserveRequest attaches a bounded request-body capture to req. It is meant to be used as a client request observer, so it sees initial requests, redirect requests, retries, and Digest replays.

type Request

type Request struct {
	Method      string      `json:"method"`
	URL         string      `json:"url"`
	HTTPVersion string      `json:"httpVersion"`
	Headers     []NameValue `json:"headers"`
	Cookies     []Cookie    `json:"cookies"`
	QueryString []NameValue `json:"queryString"`
	PostData    *PostData   `json:"postData,omitempty"`
	HeadersSize int64       `json:"headersSize"`
	BodySize    int64       `json:"bodySize"`
}

type Response

type Response struct {
	Status      int         `json:"status"`
	StatusText  string      `json:"statusText"`
	HTTPVersion string      `json:"httpVersion"`
	Headers     []NameValue `json:"headers"`
	Cookies     []Cookie    `json:"cookies"`
	Content     Content     `json:"content"`
	RedirectURL string      `json:"redirectURL"`
	HeadersSize int64       `json:"headersSize"`
	BodySize    int64       `json:"bodySize"`
}

type ResponseCapture

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

ResponseCapture is an io.Writer suitable for body.Stream.AddTee.

func (*ResponseCapture) Size

func (c *ResponseCapture) Size() int64

Size reports the number of decoded response bytes observed by the tee.

func (*ResponseCapture) Write

func (c *ResponseCapture) Write(p []byte) (int, error)

type Timings

type Timings struct {
	DNS           time.Duration
	Connect       time.Duration
	TLS           time.Duration
	Wait          time.Duration
	Receive       time.Duration
	TransferSize  int64
	TransferKnown bool
	RemoteIP      string
	DNSKnown      bool
	ConnectKnown  bool
	TLSKnown      bool
	WaitKnown     bool
	ReceiveKnown  bool
	CompletedAt   time.Time
}

Timings contains the measurements available from the request transport. Values are converted to HAR milliseconds when the entry is written.

type TimingsHAR

type TimingsHAR struct {
	Blocked float64 `json:"blocked"`
	DNS     float64 `json:"dns"`
	Connect float64 `json:"connect"`
	SSL     float64 `json:"ssl"`
	Send    float64 `json:"send"`
	Wait    float64 `json:"wait"`
	Receive float64 `json:"receive"`
}

Jump to

Keyboard shortcuts

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