storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateHAR

func GenerateHAR(records []*RequestRecord) ([]byte, error)

GenerateHAR converts stored RequestRecords into a standard HAR 1.2 JSON structure.

Types

type HAR

type HAR struct {
	Log HARLog `json:"log"`
}

HAR represents the root HTTP Archive 1.2 container.

type HARContent

type HARContent struct {
	Size     int    `json:"size"`
	MimeType string `json:"mimeType"`
	Text     string `json:"text,omitempty"`
}

type HARCookie

type HARCookie struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Path     string `json:"path,omitempty"`
	Domain   string `json:"domain,omitempty"`
	Secure   bool   `json:"secure,omitempty"`
	HTTPOnly bool   `json:"httpOnly,omitempty"`
}

type HARCreator

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

type HAREntry

type HAREntry struct {
	StartedDateTime time.Time   `json:"startedDateTime"`
	Time            float64     `json:"time"` // duration in milliseconds
	Request         HARRequest  `json:"request"`
	Response        HARResponse `json:"response"`
	Cache           struct{}    `json:"cache"`
	Timings         HARTimings  `json:"timings"`
	ServerIPAddress string      `json:"serverIPAddress,omitempty"`
}

type HARHeader

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

type HARLog

type HARLog struct {
	Version string     `json:"version"`
	Creator HARCreator `json:"creator"`
	Entries []HAREntry `json:"entries"`
}

type HARPostData

type HARPostData struct {
	MimeType string `json:"mimeType"`
	Text     string `json:"text"`
}

type HARQuery

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

type HARRequest

type HARRequest struct {
	Method      string       `json:"method"`
	URL         string       `json:"url"`
	HTTPVersion string       `json:"httpVersion"`
	Headers     []HARHeader  `json:"headers"`
	QueryString []HARQuery   `json:"queryString"`
	Cookies     []HARCookie  `json:"cookies"`
	HeaderSize  int          `json:"headersSize"`
	BodySize    int          `json:"bodySize"`
	PostData    *HARPostData `json:"postData,omitempty"`
}

type HARResponse

type HARResponse struct {
	Status      int         `json:"status"`
	StatusText  string      `json:"statusText"`
	HTTPVersion string      `json:"httpVersion"`
	Headers     []HARHeader `json:"headers"`
	Cookies     []HARCookie `json:"cookies"`
	Content     HARContent  `json:"content"`
	RedirectURL string      `json:"redirectURL"`
	HeaderSize  int         `json:"headersSize"`
	BodySize    int         `json:"bodySize"`
}

type HARTimings

type HARTimings struct {
	Send    float64 `json:"send"`
	Wait    float64 `json:"wait"`
	Receive float64 `json:"receive"`
}

type RequestRecord

type RequestRecord struct {
	ID           string              `json:"id"`
	Timestamp    time.Time           `json:"timestamp"`
	DurationMs   float64             `json:"duration_ms"`
	ClientIP     string              `json:"client_ip"`
	Scheme       string              `json:"scheme"`
	Host         string              `json:"host"`
	Method       string              `json:"method"`
	Path         string              `json:"path"`
	URL          string              `json:"url"`
	Proto        string              `json:"proto"`
	StatusCode   int                 `json:"status_code"`
	ReqHeaders   map[string][]string `json:"req_headers"`
	ReqBody      string              `json:"req_body"`
	RespHeaders  map[string][]string `json:"resp_headers"`
	RespBody     string              `json:"resp_body"`
	TLS          bool                `json:"tls"`
	FindingCount int                 `json:"finding_count"`
	Findings     []*analysis.Finding `json:"findings,omitempty"`
}

RequestRecord represents stored HTTP transaction metadata.

type StatsSummary

type StatsSummary struct {
	TotalRequests   int64            `json:"total_requests"`
	TotalFindings   int64            `json:"total_findings"`
	SeverityCounts  map[string]int64 `json:"severity_counts"`
	AvgLatencyMs    float64          `json:"avg_latency_ms"`
	TotalBytesTrans int64            `json:"total_bytes"`
}

StatsSummary contains high-level metrics for the dashboard.

type Store

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

Store provides an ephemeral in-memory SQLite database for captured requests and security findings.

func NewStore

func NewStore() (*Store, error)

NewStore initializes a new in-memory SQLite store with schema and indexes.

func (*Store) ClearAll

func (s *Store) ClearAll() error

ClearAll deletes all stored requests and findings.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection.

func (*Store) GetRecentFindings

func (s *Store) GetRecentFindings(limit int, severity string) ([]*analysis.Finding, error)

GetRecentFindings returns latest security findings.

func (*Store) GetRecentRequests

func (s *Store) GetRecentRequests(limit int, query string) ([]*RequestRecord, error)

GetRecentRequests retrieves the latest requests up to limit.

func (*Store) GetRequestByID

func (s *Store) GetRequestByID(id string) (*RequestRecord, error)

GetRequestByID retrieves full request and response pair along with any findings.

func (*Store) GetStats

func (s *Store) GetStats() (*StatsSummary, error)

GetStats returns summary metrics for the dashboard.

func (*Store) PruneOldRecords

func (s *Store) PruneOldRecords(keepCount int) error

PruneOldRecords deletes records exceeding keepCount to prevent memory growth in long sessions.

func (*Store) SaveTransaction

func (s *Store) SaveTransaction(event *ringbuffer.TrafficEvent, findings []*analysis.Finding) error

SaveTransaction inserts a request event along with any findings into SQLite.

Jump to

Keyboard shortcuts

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