proxy

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 24 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStructFromFile added in v1.6.0

func NewStructFromFile[T any](filename string) (*T, error)

Types

type Addon added in v1.0.0

type Addon interface {
	// A client has connected to mitmproxy. Note that a connection can correspond to multiple HTTP requests.
	ClientConnected(*ClientConn)

	// A client connection has been closed (either by us or the client).
	ClientDisconnected(*ClientConn)

	// Mitmproxy has connected to a server.
	ServerConnected(*ConnContext)

	// A server connection has been closed (either by us or the server).
	ServerDisconnected(*ConnContext)

	// The TLS handshake with the server has been completed successfully.
	TlsEstablishedServer(*ConnContext)

	// HTTP request headers were successfully read. At this point, the body is empty.
	Requestheaders(*Flow)

	// The full HTTP request has been read.
	Request(*Flow)

	// HTTP response headers were successfully read. At this point, the body is empty.
	Responseheaders(*Flow)

	// The full HTTP response has been read.
	Response(*Flow)

	// Stream request body modifier
	StreamRequestModifier(*Flow, io.Reader) io.Reader

	// Stream response body modifier
	StreamResponseModifier(*Flow, io.Reader) io.Reader

	// onAccessProxyServer
	AccessProxyServer(req *http.Request, res http.ResponseWriter)
}

type BaseAddon added in v1.0.0

type BaseAddon struct{}

BaseAddon do nothing

func (*BaseAddon) AccessProxyServer added in v1.6.2

func (addon *BaseAddon) AccessProxyServer(req *http.Request, res http.ResponseWriter)

func (*BaseAddon) ClientConnected added in v1.0.0

func (addon *BaseAddon) ClientConnected(*ClientConn)

func (*BaseAddon) ClientDisconnected added in v1.0.0

func (addon *BaseAddon) ClientDisconnected(*ClientConn)

func (*BaseAddon) Request added in v1.0.0

func (addon *BaseAddon) Request(*Flow)

func (*BaseAddon) Requestheaders added in v1.0.0

func (addon *BaseAddon) Requestheaders(*Flow)

func (*BaseAddon) Response added in v1.0.0

func (addon *BaseAddon) Response(*Flow)

func (*BaseAddon) Responseheaders added in v1.0.0

func (addon *BaseAddon) Responseheaders(*Flow)

func (*BaseAddon) ServerConnected added in v1.0.0

func (addon *BaseAddon) ServerConnected(*ConnContext)

func (*BaseAddon) ServerDisconnected added in v1.0.0

func (addon *BaseAddon) ServerDisconnected(*ConnContext)

func (*BaseAddon) StreamRequestModifier added in v1.1.0

func (addon *BaseAddon) StreamRequestModifier(f *Flow, in io.Reader) io.Reader

func (*BaseAddon) StreamResponseModifier added in v1.1.0

func (addon *BaseAddon) StreamResponseModifier(f *Flow, in io.Reader) io.Reader

func (*BaseAddon) TlsEstablishedServer added in v1.0.0

func (addon *BaseAddon) TlsEstablishedServer(*ConnContext)

type ClientConn added in v1.0.0

type ClientConn struct {
	Id           uuid.UUID
	Conn         net.Conn
	Tls          bool
	UpstreamCert bool // Connect to upstream server to look up certificate details. Default: True
	// contains filtered or unexported fields
}

client connection

func (*ClientConn) MarshalJSON added in v1.0.0

func (c *ClientConn) MarshalJSON() ([]byte, error)

type ConnContext added in v1.0.0

type ConnContext struct {
	ClientConn *ClientConn `json:"clientConn"`
	ServerConn *ServerConn `json:"serverConn"`
	Intercept  bool        `json:"intercept"` // Indicates whether to parse HTTPS
	FlowCount  uint32      `json:"-"`         // Number of HTTP requests made on the same connection
	// contains filtered or unexported fields
}

connection context

func (*ConnContext) Id added in v1.0.0

func (connCtx *ConnContext) Id() uuid.UUID

type Flow added in v1.0.0

type Flow struct {
	Id          uuid.UUID
	ConnContext *ConnContext
	Request     *Request
	Response    *Response

	// https://docs.mitmproxy.org/stable/overview-features/#streaming
	// 如果为 true,则不缓冲 Request.Body 和 Response.Body,且不进入之后的 Addon.Request 和 Addon.Response
	Stream            bool
	UseSeparateClient bool // use separate http client to send http request
	// contains filtered or unexported fields
}

flow

func (*Flow) Done added in v1.0.0

func (f *Flow) Done() <-chan struct{}

func (*Flow) MarshalJSON added in v1.0.0

func (f *Flow) MarshalJSON() ([]byte, error)

type LogAddon added in v1.0.0

type LogAddon struct {
	BaseAddon
}

LogAddon log connection and flow

func (*LogAddon) ClientConnected added in v1.0.0

func (addon *LogAddon) ClientConnected(client *ClientConn)

func (*LogAddon) ClientDisconnected added in v1.0.0

func (addon *LogAddon) ClientDisconnected(client *ClientConn)

func (*LogAddon) Requestheaders added in v1.0.0

func (addon *LogAddon) Requestheaders(f *Flow)

func (*LogAddon) ServerConnected added in v1.0.0

func (addon *LogAddon) ServerConnected(connCtx *ConnContext)

func (*LogAddon) ServerDisconnected added in v1.0.0

func (addon *LogAddon) ServerDisconnected(connCtx *ConnContext)

type Options

type Options struct {
	Debug             int
	Addr              string
	StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式
	SslInsecure       bool
	CaRootPath        string
	Upstream          string
}

type Proxy

type Proxy struct {
	Opts    *Options
	Version string
	Addons  []Addon
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy(opts *Options) (*Proxy, error)

func (*Proxy) AddAddon

func (proxy *Proxy) AddAddon(addon Addon)

func (*Proxy) Close added in v1.3.0

func (proxy *Proxy) Close() error

func (*Proxy) GetCertificate added in v1.3.4

func (proxy *Proxy) GetCertificate() x509.Certificate

func (*Proxy) ServeHTTP

func (proxy *Proxy) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*Proxy) SetShouldInterceptRule added in v1.3.4

func (proxy *Proxy) SetShouldInterceptRule(rule func(req *http.Request) bool)

func (*Proxy) SetUpstreamProxy added in v1.7.0

func (proxy *Proxy) SetUpstreamProxy(fn func(req *http.Request) (*url.URL, error))

func (*Proxy) Shutdown added in v1.3.0

func (proxy *Proxy) Shutdown(ctx context.Context) error

func (*Proxy) Start

func (proxy *Proxy) Start() error

type Request added in v1.0.0

type Request struct {
	Method string
	URL    *url.URL
	Proto  string
	Header http.Header
	Body   []byte
	// contains filtered or unexported fields
}

flow http request

func (*Request) MarshalJSON added in v1.0.0

func (req *Request) MarshalJSON() ([]byte, error)

func (*Request) Raw added in v1.0.0

func (r *Request) Raw() *http.Request

func (*Request) UnmarshalJSON added in v1.0.0

func (req *Request) UnmarshalJSON(data []byte) error

type Response added in v1.0.0

type Response struct {
	StatusCode int         `json:"statusCode"`
	Header     http.Header `json:"header"`
	Body       []byte      `json:"-"`
	BodyReader io.Reader
	// contains filtered or unexported fields
}

flow http response

func (*Response) DecodedBody added in v1.0.0

func (r *Response) DecodedBody() ([]byte, error)

func (*Response) IsTextContentType added in v1.0.0

func (r *Response) IsTextContentType() bool

func (*Response) ReplaceToDecodedBody added in v1.0.0

func (r *Response) ReplaceToDecodedBody()

type ServerConn added in v1.0.0

type ServerConn struct {
	Id      uuid.UUID
	Address string
	Conn    net.Conn
	// contains filtered or unexported fields
}

server connection

func (*ServerConn) MarshalJSON added in v1.0.0

func (c *ServerConn) MarshalJSON() ([]byte, error)

func (*ServerConn) TlsState added in v1.0.0

func (c *ServerConn) TlsState() *tls.ConnectionState

Jump to

Keyboard shortcuts

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