proxy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package proxy implements the MitM Proxy (Forward Proxy).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addon

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
}

type BaseAddon

type BaseAddon struct{}

BaseAddon do nothing

func (*BaseAddon) ClientConnected

func (addon *BaseAddon) ClientConnected(*ClientConn)

func (*BaseAddon) ClientDisconnected

func (addon *BaseAddon) ClientDisconnected(*ClientConn)

func (*BaseAddon) Request

func (addon *BaseAddon) Request(*Flow)

func (*BaseAddon) Requestheaders

func (addon *BaseAddon) Requestheaders(*Flow)

func (*BaseAddon) Response

func (addon *BaseAddon) Response(*Flow)

func (*BaseAddon) Responseheaders

func (addon *BaseAddon) Responseheaders(*Flow)

func (*BaseAddon) ServerConnected

func (addon *BaseAddon) ServerConnected(*ConnContext)

func (*BaseAddon) ServerDisconnected

func (addon *BaseAddon) ServerDisconnected(*ConnContext)

func (*BaseAddon) StreamRequestModifier

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

func (*BaseAddon) StreamResponseModifier

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

func (*BaseAddon) TlsEstablishedServer

func (addon *BaseAddon) TlsEstablishedServer(*ConnContext)

type ClientConn

type ClientConn struct {
	ID   uuid.UUID       `json:"id"`
	Conn *wrapClientConn `json:"-"`
	TLS  bool            `json:"tls"`
}

client connection

func (*ClientConn) MarshalJSON

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

type ConnContext

type ConnContext struct {
	ClientConn *ClientConn `json:"clientConn"`
	ServerConn *ServerConn `json:"serverConn"`
	// contains filtered or unexported fields
}

connection context

func (*ConnContext) ID

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

type Flow

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
	// contains filtered or unexported fields
}

flow

func (*Flow) Done

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

func (*Flow) MarshalJSON

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

type Options

type Options struct {
	Debug                 int
	Addr                  string
	StreamLargeBodies     int64 // When the request or response body is larger then this in bytes, turn into stream model.
	InsecureSkipVerifyTLS bool
	CA                    cert.Getter
}

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

func (proxy *Proxy) Close() error

func (*Proxy) ServeHTTP

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

func (*Proxy) Shutdown

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

func (*Proxy) Start

func (proxy *Proxy) Start() error

type Request

type Request struct {
	Method string      `json:"method"`
	URL    *url.URL    `json:"url"`
	Proto  string      `json:"proto"`
	Header http.Header `json:"header"`
	Body   []byte      `json:"-"`
	// contains filtered or unexported fields
}

flow http request

func (*Request) MarshalJSON

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

func (*Request) Raw

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

func (*Request) UnmarshalJSON

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

func (*Request) WithAttribute

func (r *Request) WithAttribute(key string, val any)

type Response

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

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

func (*Response) IsTextContentType

func (r *Response) IsTextContentType() bool

func (*Response) ReplaceToDecodedBody

func (r *Response) ReplaceToDecodedBody()

type ServerConn

type ServerConn struct {
	ID      uuid.UUID `json:"id"`
	Address string    `json:"address"`
	Conn    net.Conn  `json:"-"`
	// contains filtered or unexported fields
}

server connection

func (*ServerConn) MarshalJSON

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

func (*ServerConn) TLSState

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

Jump to

Keyboard shortcuts

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