Documentation
¶
Overview ¶
Package capture provides traffic capture functionality for the proxy.
Index ¶
- type Capturer
- func (c *Capturer) AddHandler(h Handler)
- func (c *Capturer) Clear()
- func (c *Capturer) FinishCapture(rec *Record, resp *http.Response) error
- func (c *Capturer) FinishCaptureWithStatus(rec *Record, statusCode int, bytesWritten int64) error
- func (c *Capturer) Records() []Record
- func (c *Capturer) StartCapture(req *http.Request) *Record
- type Config
- type Filter
- type Format
- type HAR
- type HARCache
- type HARContent
- type HARCookie
- type HARCreator
- type HAREntry
- type HARHeader
- type HARLog
- type HARPostData
- type HARPostParam
- type HARQueryPair
- type HARRequest
- type HARResponse
- type HARTimings
- type HARWriter
- type Handler
- type Record
- type RequestRecord
- type ResponseRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capturer ¶
type Capturer struct {
// contains filtered or unexported fields
}
Capturer captures HTTP transactions.
func NewCapturer ¶
NewCapturer creates a new traffic capturer.
func (*Capturer) AddHandler ¶
AddHandler adds a handler to be called for each captured record.
func (*Capturer) FinishCapture ¶
FinishCapture completes capturing a response.
func (*Capturer) FinishCaptureWithStatus ¶
FinishCaptureWithStatus completes capturing with just status code and size (for reverse proxy).
type Config ¶
type Config struct {
// Output is where to write captured traffic (default: stdout)
Output io.Writer
// Format is the output format (default: ndjson)
Format Format
// IncludeHeaders controls whether to include headers
IncludeHeaders bool
// FilterHeaders is a list of headers to exclude (case-insensitive)
FilterHeaders []string
// IncludeBody controls whether to include request/response bodies
IncludeBody bool
// MaxBodySize is the maximum body size to capture (default: 1MB)
MaxBodySize int64
// SkipBinary skips capturing binary content (images, videos, etc.)
SkipBinary bool
// Filter is the request/response filter (optional)
Filter *Filter
}
Config holds capturer configuration.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default capturer configuration.
type Filter ¶
type Filter struct {
// IncludeHosts is a list of hosts to include (supports wildcards)
IncludeHosts []string
// ExcludeHosts is a list of hosts to exclude (supports wildcards)
ExcludeHosts []string
// IncludePaths is a list of path patterns to include (supports wildcards)
IncludePaths []string
// ExcludePaths is a list of path patterns to exclude (supports wildcards)
ExcludePaths []string
// IncludeMethods is a list of HTTP methods to include
IncludeMethods []string
// ExcludeMethods is a list of HTTP methods to exclude
ExcludeMethods []string
// IncludeStatusCodes is a list of status codes to include
IncludeStatusCodes []int
// ExcludeStatusCodes is a list of status codes to exclude
ExcludeStatusCodes []int
// MinStatusCode is the minimum status code to include
MinStatusCode int
// MaxStatusCode is the maximum status code to include
MaxStatusCode int
// contains filtered or unexported fields
}
Filter defines criteria for including/excluding requests.
func (*Filter) MatchRequest ¶
MatchRequest checks if a request matches the filter criteria.
func (*Filter) MatchResponse ¶
MatchResponse checks if a response matches the filter criteria.
type Format ¶
type Format string
Format specifies the output format for captured traffic.
const ( // FormatJSON outputs records as JSON objects FormatJSON Format = "json" // FormatNDJSON outputs records as newline-delimited JSON FormatNDJSON Format = "ndjson" // FormatHAR outputs records in HAR format FormatHAR Format = "har" // FormatIR outputs records in APISpecRift IR format FormatIR Format = "ir" )
type HARContent ¶
type HARContent struct {
Size int64 `json:"size"`
MimeType string `json:"mimeType"`
Text string `json:"text,omitempty"`
Encoding string `json:"encoding,omitempty"`
}
HARContent represents response content.
type HARCookie ¶
type HARCookie 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,omitempty"`
Secure bool `json:"secure,omitempty"`
}
HARCookie represents a cookie.
type HARCreator ¶
HARCreator identifies the tool that created the HAR.
type HAREntry ¶
type HAREntry struct {
StartedDateTime string `json:"startedDateTime"`
Time float64 `json:"time"`
Request HARRequest `json:"request"`
Response HARResponse `json:"response"`
Cache HARCache `json:"cache"`
Timings HARTimings `json:"timings"`
}
HAREntry represents a single HTTP transaction.
type HARLog ¶
type HARLog struct {
Version string `json:"version"`
Creator HARCreator `json:"creator"`
Entries []HAREntry `json:"entries"`
}
HARLog is the root of the HAR format.
type HARPostData ¶
type HARPostData struct {
MimeType string `json:"mimeType"`
Text string `json:"text,omitempty"`
Params []HARPostParam `json:"params,omitempty"`
}
HARPostData represents POST data.
type HARPostParam ¶
type HARPostParam struct {
Name string `json:"name"`
Value string `json:"value,omitempty"`
FileName string `json:"fileName,omitempty"`
ContentType string `json:"contentType,omitempty"`
}
HARPostParam represents a POST parameter.
type HARQueryPair ¶
HARQueryPair represents a query string parameter.
type HARRequest ¶
type HARRequest struct {
Method string `json:"method"`
URL string `json:"url"`
HTTPVersion string `json:"httpVersion"`
Cookies []HARCookie `json:"cookies"`
Headers []HARHeader `json:"headers"`
QueryString []HARQueryPair `json:"queryString"`
PostData *HARPostData `json:"postData,omitempty"`
HeadersSize int `json:"headersSize"`
BodySize int `json:"bodySize"`
}
HARRequest represents an HTTP request.
type HARResponse ¶
type HARResponse struct {
Status int `json:"status"`
StatusText string `json:"statusText"`
HTTPVersion string `json:"httpVersion"`
Cookies []HARCookie `json:"cookies"`
Headers []HARHeader `json:"headers"`
Content HARContent `json:"content"`
RedirectURL string `json:"redirectURL"`
HeadersSize int `json:"headersSize"`
BodySize int `json:"bodySize"`
}
HARResponse represents an HTTP response.
type HARTimings ¶
type HARTimings struct {
Blocked float64 `json:"blocked"`
DNS float64 `json:"dns"`
Connect float64 `json:"connect"`
Send float64 `json:"send"`
Wait float64 `json:"wait"`
Receive float64 `json:"receive"`
SSL float64 `json:"ssl"`
}
HARTimings represents timing information.
type HARWriter ¶
type HARWriter struct {
// contains filtered or unexported fields
}
HARWriter writes records in HAR format.
func NewHARWriter ¶
NewHARWriter creates a new HAR writer.
type Record ¶
type Record struct {
// Request information
Request RequestRecord `json:"request"`
// Response information
Response ResponseRecord `json:"response,omitempty"`
// Timing information
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime,omitempty"`
DurationMs float64 `json:"durationMs,omitempty"`
}
Record represents a captured HTTP transaction.
type RequestRecord ¶
type RequestRecord struct {
Method string `json:"method"`
URL string `json:"url"`
Host string `json:"host"`
Path string `json:"path"`
Scheme string `json:"scheme"`
Headers map[string]string `json:"headers,omitempty"`
Query map[string]string `json:"query,omitempty"`
Body interface{} `json:"body,omitempty"`
BodySize int64 `json:"bodySize,omitempty"`
IsBinary bool `json:"isBinary,omitempty"`
ContentType string `json:"contentType,omitempty"`
}
RequestRecord represents a captured HTTP request.
type ResponseRecord ¶
type ResponseRecord struct {
Status int `json:"status"`
StatusText string `json:"statusText,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Body interface{} `json:"body,omitempty"`
IsBinary bool `json:"isBinary,omitempty"`
ContentType string `json:"contentType,omitempty"`
Size int64 `json:"size,omitempty"`
}
ResponseRecord represents a captured HTTP response.