intercept

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package intercept implements the request hold queue (Burp-style intercept) and the request-side match-&-replace engine. The proxy calls Hold on every request; when intercept is enabled the calling goroutine blocks until the UI forwards (optionally with edits) or drops it.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotHeld = errors.New("intercept: request not held")

ErrNotHeld is returned when resolving an id that is not (or no longer) held.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Drop    bool
	Edited  bool
	Held    bool // the request actually entered the hold queue (vs. filtered straight through)
	Request *http.Request
}

Decision is the outcome of a hold: forward the (possibly edited) request, or drop it.

type Engine

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

Engine owns the hold queue and the compiled rule set.

func New

func New() *Engine

New returns an Engine with intercept disabled and no rules.

func (*Engine) ApplyResponseRules

func (e *Engine) ApplyResponseRules(h http.Header, body []byte) (http.Header, []byte)

ApplyResponseRules applies enabled response-side rules to a response's headers and body, returning the transformed pair.

func (*Engine) ApplyRules

func (e *Engine) ApplyRules(req *http.Request) error

ApplyRules mutates req per the enabled request-side rules, in order.

func (*Engine) Drop

func (e *Engine) Drop(id int64) error

Drop releases a held request as dropped (never forwarded).

func (*Engine) DropResponse

func (e *Engine) DropResponse(id int64) error

DropResponse drops a held response (client receives nothing).

func (*Engine) Enabled

func (e *Engine) Enabled() bool

Enabled reports whether intercept is on.

func (*Engine) Forward

func (e *Engine) Forward(id int64, editedRaw []byte) error

Forward releases a held request. If editedRaw is non-empty it replaces the request with the re-parsed edited version (forwarding target preserved).

func (*Engine) ForwardResponse

func (e *Engine) ForwardResponse(id int64, editedRaw []byte) error

ForwardResponse releases a held response (optionally replacing its raw bytes).

func (*Engine) HasResponseRules

func (e *Engine) HasResponseRules() bool

HasResponseRules reports whether any enabled response-side rule exists.

func (*Engine) Hold

func (e *Engine) Hold(flow *store.Flow, req *http.Request, raw []byte) Decision

Hold submits a request to the gate. If intercept is off it returns immediately with a forward decision; otherwise it blocks until the UI resolves it. raw is the editable origin-form snapshot shown in the UI.

func (*Engine) HoldResponse

func (e *Engine) HoldResponse(flow *store.Flow, raw []byte) ResponseDecision

HoldResponse blocks (when response interception is on) until the UI forwards or drops the response. raw is the editable response snapshot.

func (*Engine) InterceptFilter added in v0.3.0

func (e *Engine) InterceptFilter() (bool, string, string)

InterceptFilter returns the current filter (enabled, target, pattern).

func (*Engine) Queue

func (e *Engine) Queue() []Held

Queue returns a snapshot of held requests in arrival order.

func (*Engine) ResponseEnabled

func (e *Engine) ResponseEnabled() bool

ResponseEnabled reports whether response interception is on.

func (*Engine) ResponseQueue

func (e *Engine) ResponseQueue() []HeldResponse

ResponseQueue returns a snapshot of held responses in arrival order.

func (*Engine) SetEnabled

func (e *Engine) SetEnabled(on bool)

SetEnabled toggles intercept. Turning it off forwards everything currently held.

func (*Engine) SetInterceptFilter added in v0.3.0

func (e *Engine) SetInterceptFilter(enabled bool, target, pattern string) error

SetInterceptFilter configures the conditional-intercept filter. When enabled with a valid pattern, only requests whose chosen field matches the regex are held. An invalid regex is returned as an error and the filter is left unchanged.

func (*Engine) SetNotifier

func (e *Engine) SetNotifier(fn func())

SetNotifier registers a callback invoked whenever the queue changes.

func (*Engine) SetResponseEnabled

func (e *Engine) SetResponseEnabled(on bool)

SetResponseEnabled toggles response interception. Turning it off forwards everything currently held (unchanged).

func (*Engine) SetRules

func (e *Engine) SetRules(rules []store.Rule) error

SetRules compiles and installs the rule set, rejecting invalid regexes.

type Held

type Held struct {
	ID   int64
	Flow *store.Flow
	Raw  []byte // origin-form raw request bytes, editable before forwarding
}

Held is a UI-facing snapshot of a request waiting in the hold queue.

type HeldResponse

type HeldResponse struct {
	ID   int64
	Flow *store.Flow
	Raw  []byte
}

HeldResponse is a UI-facing snapshot of a response waiting in the hold queue.

type ResponseDecision

type ResponseDecision struct {
	Drop   bool
	Edited bool
	Raw    []byte // the raw response bytes to send to the client
}

ResponseDecision is the outcome of holding a response: forward the (possibly edited) raw response, or drop it.

Jump to

Keyboard shortcuts

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