mitm

package
v0.0.0-...-6ba55b6 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(proxyURL *url.URL, hostnameRunningComplement string) *Client

func (*Client) Configure

func (m *Client) Configure(t *testing.T) *Configuration

func (*Client) LockOptions

func (m *Client) LockOptions(t *testing.T, options map[string]any) (lockID []byte)

Lock mitmproxy with the given set of options.

If mitmproxy is already locked, this will fail the test. This is a low-level function which provides an escape hatch if the test needs special mitmproxy options. See https://docs.mitmproxy.org/stable/concepts-options/ for more information about options.

In general, tests should not call this function, preferring to use .Configure which has a friendlier API shape.

func (*Client) UnlockOptions

func (m *Client) UnlockOptions(t *testing.T, lockID []byte)

Unlock mitmproxy using the lock ID provided.

If mitmproxy is already unlocked, this will fail the test. If the lock ID does not match the ID of the existing lock, this will fail the test. This is a low-level function which provides an escape hatch if the test needs special mitmproxy options. See https://docs.mitmproxy.org/stable/concepts-options/ for more information about options.

In general, tests should not call this function, preferring to use .Configure which has a friendlier API shape.

type Configuration

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

Configuration represent a single mitmproxy configuration, with all options specified.

Tests will typically build up this configuration by calling `Intercept` with the paths they are interested in.

func (*Configuration) WithIntercept

func (c *Configuration) WithIntercept(opts InterceptOpts, inner func())

WithIntercept provides the intercept options to mitmproxy, and calls the `inner` function whilst that configuration has been applied. mitmproxy will revert back to its default configuration when `inner` returns.

type Filter

type Filter interface {
	FilterString() string
}

Filter represents a mitmproxy filter; see https://docs.mitmproxy.org/stable/concepts-filters/ for more information.

Filters can either be specified directly as a filter expression string (see FilterExpression), or they can be built up in code (see FilterParams). In general, tests should use FilterParams, and only use the FilterExpression escape hatch if they cannot express the precise filtering rules with FilterParams.

type FilterExpression

type FilterExpression string

FilterExpression represents a mitmproxy filter expression e.g. "~m PUT ~hq syt_aabbccddeeff"

func (FilterExpression) FilterString

func (s FilterExpression) FilterString() string

type FilterParams

type FilterParams struct {
	// The URL path must contain this string to match.
	// If unset, no path filtering is applied.
	PathContains string
	// The access token which must appear as a header.
	// If unset, no access token filtering is applied.
	AccessToken string
	// The HTTP method which must be used for this to match.
	// If unset, no HTTP method filtering is applied.
	Method string
}

FilterParams represents the set of filters which are AND'd together to form the final filter.

func (FilterParams) FilterString

func (p FilterParams) FilterString() string

type InterceptOpts

type InterceptOpts struct {
	// Which HTTP requests/responses should be caught for this configuration.
	// Any HTTP request/response which does not meet this filter criteria will
	// be passed through without invoking the callback function. If no Filter
	// is provided, all HTTP requests/responses will be caught and the respective
	// callback called for each.
	Filter Filter
	// The function to invoke when an HTTP request has met the filter
	// criteria. This callback is invoked BEFORE the request reaches the server.
	// If this callback function returns a response, the request will never
	// reach the server and the response provided will be returned instead.
	// If this callback function returns nil, or no request callback function
	// is provided, requests will be passed to the server unaltered.
	RequestCallback callback.Fn
	// The function to invoke when an HTTP response has met the filter
	// criteria. This callback is invoked AFTER the request has been processed
	// by the server. If this callback function returns a response, the
	// server response will never reach the client and the response provided
	// will be returned instead. If this callback function returns nil, or no
	// response callback function is provided, responses will be passed to the
	// client unaltered.
	ResponseCallback callback.Fn
}

InterceptOpts specifies the desired configuration for mitmproxy

Jump to

Keyboard shortcuts

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