Documentation
¶
Overview ¶
Package har provides HAR 1.2 types and an HTTP client middleware for capturing outbound request/response pairs for troubleshooting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶
func NewMiddleware(cfg HARConfig, handler func(*Entry)) middlewares.Middleware
NewMiddleware returns a middlewares.Middleware that captures each request/response pair into a *Entry and calls handler. If handler is nil, the middleware is a no-op.
Types ¶
type Cache ¶
type Cache struct{}
Cache holds cache information for an entry (required by spec; left empty by hx).
type Collector ¶
type Collector struct {
Config HARConfig
// contains filtered or unexported fields
}
Collector accumulates HAR entries from multiple sources (main requests, OAuth token fetches, redirect hops, retries).
func NewCollector ¶
func (*Collector) Handler ¶
Handler returns a func(*Entry) that adds entries to this collector. Useful for passing to components that accept a HAR handler callback.
func (*Collector) Middleware ¶
func (c *Collector) Middleware() middlewares.Middleware
Middleware returns a transport middleware that captures each request/response into this collector.
type Content ¶
type Content struct {
Size int64 `json:"size"`
MimeType string `json:"mimeType,omitempty"`
Text string `json:"text,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
Content holds the response body details.
type Entry ¶
type Entry struct {
StartedDateTime string `json:"startedDateTime"`
Time float64 `json:"time"`
Request Request `json:"request"`
Response Response `json:"response"`
Cache Cache `json:"cache"`
Timings Timings `json:"timings"`
}
Entry represents a single HTTP request/response pair.
type File ¶
type File struct {
Log Log `json:"log"`
}
File is the outermost HAR 1.2 envelope: {"log": {...}}. Use this when writing .har files for import into browser DevTools.
type HARConfig ¶
type HARConfig struct {
// MaxBodySize is the maximum number of bytes captured per body.
// Bodies exceeding this are truncated and Content.Truncated is set to true.
// Default: 65536 (64 KB).
MaxBodySize int64
// CaptureContentTypes lists MIME type prefixes for which body capture is enabled.
// Default: ["application/json", "application/x-www-form-urlencoded"].
CaptureContentTypes []string
// RedactedHeaders lists additional header name glob patterns to redact,
// on top of logger.CommonRedactedHeaders.
RedactedHeaders []string
}
HARConfig controls what the HAR middleware captures and how it redacts.
func DefaultConfig ¶
func DefaultConfig() HARConfig
DefaultConfig returns a HARConfig with sensible defaults.
type Log ¶
type Log struct {
Version string `json:"version"`
Creator Creator `json:"creator"`
Pages []Page `json:"pages"`
Entries []Entry `json:"entries"`
}
Log is the top-level HAR 1.2 container.
type Page ¶
type Page struct {
StartedDateTime string `json:"startedDateTime"`
ID string `json:"id"`
Title string `json:"title"`
PageTimings PageTimings `json:"pageTimings"`
}
Page is included for HAR 1.2 spec compliance; hx leaves it empty.
type PageTimings ¶
type PageTimings struct {
OnLoad int `json:"onLoad,omitempty"`
}
PageTimings holds page-level timing data (unused by hx, present for spec compliance).
type QueryString ¶
QueryString is a name/value pair from the URL query string.
type Request ¶
type Request struct {
Method string `json:"method"`
URL string `json:"url"`
HTTPVersion string `json:"httpVersion"`
Cookies []Cookie `json:"cookies"`
Headers []Header `json:"headers"`
QueryString []QueryString `json:"queryString"`
PostData *PostData `json:"postData,omitempty"`
HeadersSize int `json:"headersSize"`
BodySize int64 `json:"bodySize"`
}
Request holds HAR request data.
type Response ¶
type Response struct {
Status int `json:"status"`
StatusText string `json:"statusText"`
HTTPVersion string `json:"httpVersion"`
Cookies []Cookie `json:"cookies"`
Headers []Header `json:"headers"`
Content Content `json:"content"`
RedirectURL string `json:"redirectURL"`
HeadersSize int `json:"headersSize"`
BodySize int64 `json:"bodySize"`
}
Response holds HAR response data.