### Basic go-mitmproxy Server Setup Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy This example demonstrates how to import the go-mitmproxy package and start a basic proxy server. It configures the listening address and stream large bodies. ```go package main import ( "log" "github.com/lqqyt2423/go-mitmproxy/proxy" ) func main() { opts := &proxy.Options{ Addr: ":9080", StreamLargeBodies: 1024 * 1024 * 5, } p, err := proxy.NewProxy(opts) if err != nil { log.Fatal(err) } log.Fatal(p.Start()) } ``` -------------------------------- ### Start the proxy Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Starts the proxy server and begins listening for connections. ```go func (proxy *Proxy) Start() error ``` -------------------------------- ### Install go-mitmproxy Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy Use 'go install' to install the go-mitmproxy command-line tool. This command fetches the latest version from the specified GitHub repository. ```bash go install github.com/lqqyt2423/go-mitmproxy/cmd/go-mitmproxy@latest ``` -------------------------------- ### Log WebSocket connection start Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs the establishment of a WebSocket connection. ```go func (addon *LogAddon) WebSocketStart(f *Flow) ``` -------------------------------- ### Start go-mitmproxy Proxy Server Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy Run the go-mitmproxy command to start the proxy server. The default HTTP proxy address is port 9080 and the web interface is port 9081. Certificate installation is required for HTTPS traffic. ```bash go-mitmproxy ``` -------------------------------- ### Proxy.Start Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Starts the proxy server. This method initiates the proxy's listening and traffic handling capabilities. ```APIDOC ## Proxy.Start ### Description Starts the proxy server. ### Method func (proxy *Proxy) Start() error ### Parameters None ### Response * **error**: An error if starting the proxy fails, otherwise nil. ``` -------------------------------- ### LogAddon.WebSocketStart Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs the start of a WebSocket connection. This method is part of the LogAddon type. ```APIDOC ## LogAddon.WebSocketStart ### Description Logs the start of a WebSocket connection. ### Method func (addon *LogAddon) WebSocketStart(f *Flow) ### Parameters * **f** (*Flow): The flow associated with the WebSocket connection. ### Response None ``` -------------------------------- ### Log SSE stream start Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs the start of a Server-Sent Events (SSE) stream. ```go func (addon *LogAddon) SSEStart(f *Flow) ``` -------------------------------- ### Proxy Configuration and Management Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy This section details the core functionalities for creating, configuring, and managing a proxy instance. It includes methods for starting and stopping the proxy, adding custom addons, and setting various proxy behaviors like interception rules and upstream proxy configurations. ```APIDOC ## Proxy Methods ### NewProxy Creates a new proxy instance with the given options. - **Method**: `NewProxy` - **Parameters**: - `opts` (*Options) - Required - Configuration options for the proxy. - **Returns**: - `(*Proxy, error)` - A pointer to the created Proxy instance and an error if creation fails. ### AddAddon Adds a custom addon to the proxy instance. - **Method**: `AddAddon` - **Parameters**: - `addon` (Addon) - Required - The addon to add to the proxy. ### Start Starts the proxy server. - **Method**: `Start` - **Returns**: - `error` - An error if the proxy fails to start. ### Shutdown Gracefully shuts down the proxy server. - **Method**: `Shutdown` - **Parameters**: - `ctx` (context.Context) - Required - The context for the shutdown operation. - **Returns**: - `error` - An error if the shutdown fails. ### Close Closes the proxy instance and releases resources. - **Method**: `Close` - **Returns**: - `error` - An error if closing fails. ### SetAuthProxy Sets a function to handle authentication for proxy requests. - **Method**: `SetAuthProxy` - **Parameters**: - `fn` (func(res http.ResponseWriter, req *http.Request) (bool, error)) - Required - The authentication handler function. ### SetShouldInterceptRule Sets a rule to determine whether a request should be intercepted. - **Method**: `SetShouldInterceptRule` - **Parameters**: - `rule` (func(req *http.Request) bool) - Required - The interception rule function. ### SetUpstreamProxy Sets a function to determine the upstream proxy for a given request. - **Method**: `SetUpstreamProxy` - **Parameters**: - `fn` (func(req *http.Request) (*url.URL, error)) - Required - The upstream proxy resolver function. ### GetCertificate Retrieves the proxy's root certificate. - **Method**: `GetCertificate` - **Returns**: - `x509.Certificate` - The root certificate. ### GetCertificateByCN Retrieves a TLS certificate by its common name (CN). - **Method**: `GetCertificateByCN` - **Parameters**: - `commonName` (string) - Required - The common name of the certificate to retrieve. - **Returns**: - `(*tls.Certificate, error)` - The TLS certificate and an error if retrieval fails. ``` -------------------------------- ### LogAddon.SSEStart Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs the start of an SSE stream. This method is part of the LogAddon type. ```APIDOC ## LogAddon.SSEStart ### Description Logs the start of an SSE stream. ### Method func (addon *LogAddon) SSEStart(f *Flow) ### Parameters * **f** (*Flow): The flow associated with the SSE stream. ### Response None ``` -------------------------------- ### Get proxy certificate Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Retrieves the proxy's certificate. ```go func (proxy *Proxy) GetCertificate() x509.Certificate ``` -------------------------------- ### Get certificate by Common Name Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Retrieves a TLS certificate by its Common Name. ```go func (proxy *Proxy) GetCertificateByCN(commonName string) (*tls.Certificate, error) ``` -------------------------------- ### Get decoded request body Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Retrieves and decodes the request body. ```go func (req *Request) DecodedBody() ([]byte, error) ``` -------------------------------- ### Get underlying logrus entry Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Retrieves the underlying logrus entry from an InstanceLogger. ```go func (il *InstanceLogger) GetEntry() *log.Entry ``` -------------------------------- ### Get Raw HTTP Request Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Retrieves the raw http.Request object associated with a Request. Useful for accessing underlying HTTP details. ```go func (r *Request) Raw() *http.Request ``` -------------------------------- ### Get TLS State from ServerConn Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Retrieves the TLS connection state for a given server connection. Returns nil if the connection is not using TLS. ```go func (c *ServerConn) TlsState() *tls.ConnectionState ``` -------------------------------- ### Create InstanceLogAddon with File Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Creates a new instance-aware log addon that outputs logs to a specified file. ```go func NewInstanceLogAddonWithFile(addr string, instanceName string, logFilePath string) *InstanceLogAddon ``` -------------------------------- ### Create a new proxy instance Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Initializes and returns a new Proxy instance with the given options. ```go func NewProxy(opts *Options) (*Proxy, error) ``` -------------------------------- ### BaseAddon WebSocketStart Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for WebSocketStart hook. This method does nothing. ```go func (addon *BaseAddon) WebSocketStart(*Flow) ``` -------------------------------- ### Create InstanceLogger with File Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Creates a new logger with instance identification and optional file output. ```go func NewInstanceLoggerWithFile(addr string, instanceName string, logFilePath string) *InstanceLogger ``` -------------------------------- ### View go-mitmproxy Help and Parameters Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy Use the -h flag to display all available command-line parameters for go-mitmproxy. This includes options for address, host filtering, configuration files, and more. ```bash go-mitmproxy -h ``` -------------------------------- ### NewWebAddon Constructor Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Creates and returns a new instance of WebAddon. It takes an address string as input. ```go func NewWebAddon(addr string) *WebAddon ``` -------------------------------- ### BaseAddon Request Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for Request hook. This method does nothing. ```go func (addon *BaseAddon) Request(*Flow) ``` -------------------------------- ### BaseAddon AccessProxyServer Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for AccessProxyServer hook. This method does nothing. ```go func (addon *BaseAddon) AccessProxyServer(req *http.Request, res http.ResponseWriter) ``` -------------------------------- ### Get Decoded Response Body Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Retrieves the decoded body of an HTTP response. Returns the body as a byte slice and an error if decoding fails. ```go func (r *Response) DecodedBody() ([]byte, error) ``` -------------------------------- ### BaseAddon Response Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for Response hook. This method does nothing. ```go func (addon *BaseAddon) Response(*Flow) ``` -------------------------------- ### BaseAddon SSEEnd Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for SSEEnd hook. This method does nothing. ```go func (addon *BaseAddon) SSEEnd(*Flow) ``` -------------------------------- ### BaseAddon Responseheaders Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for Responseheaders hook. This method does nothing. ```go func (addon *BaseAddon) Responseheaders(*Flow) ``` -------------------------------- ### Handle client connection Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function for when a client connects. ```go func (addon *LogAddon) ClientConnected(client *ClientConn) ``` -------------------------------- ### Handle server connection Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function for when a server connects. ```go func (addon *LogAddon) ServerConnected(connCtx *ConnContext) ``` -------------------------------- ### WebAddon WebSocketStart Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Sends a message indicating the establishment of a WebSocket connection. This method was added in v1.8.9. ```go func (web *WebAddon) WebSocketStart(f *proxy.Flow) ``` -------------------------------- ### NewMapRemoteFromFile Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Creates a new MapRemote addon instance by loading mapping rules from a specified file. ```APIDOC ## NewMapRemoteFromFile ### Description Initializes a MapRemote addon from a file, enabling remote request mapping. ### Method func NewMapRemoteFromFile(filename string) (*MapRemote, error) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response * MapRemote (pointer to MapRemote) - The initialized MapRemote addon. * error - An error if the file cannot be read or parsed. #### Response Example None ``` -------------------------------- ### InstanceLogAddon TlsEstablishedServer Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a TLS connection to the server is established. ```go func (addon *InstanceLogAddon) TlsEstablishedServer(connCtx *ConnContext) ``` -------------------------------- ### Create InstanceLogger Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Creates a new logger with instance identification. ```go func NewInstanceLogger(addr string, instanceName string) *InstanceLogger ``` -------------------------------- ### InstanceLogAddon ServerConnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a server connects. ```go func (addon *InstanceLogAddon) ServerConnected(connCtx *ConnContext) ``` -------------------------------- ### InstanceLogAddon Request Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a request is processed. ```go func (addon *InstanceLogAddon) Request(f *Flow) ``` -------------------------------- ### BaseAddon Requestheaders Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for Requestheaders hook. This method does nothing. ```go func (addon *BaseAddon) Requestheaders(*Flow) ``` -------------------------------- ### Define InstanceLogAddon Structure Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Defines the InstanceLogAddon structure for logging with instance identification. ```go type InstanceLogAddon struct { BaseAddon // contains filtered or unexported fields } ``` -------------------------------- ### InstanceLogAddon Response Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a response is processed. ```go func (addon *InstanceLogAddon) Response(f *Flow) ``` -------------------------------- ### InstanceLogAddon ClientConnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a client connects. ```go func (addon *InstanceLogAddon) ClientConnected(client *ClientConn) ``` -------------------------------- ### Add an addon to the proxy Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Registers a new addon with the proxy. ```go func (proxy *Proxy) AddAddon(addon Addon) ``` -------------------------------- ### InstanceLogAddon SetLogger Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Allows setting a custom instance logger for the addon. ```go func (addon *InstanceLogAddon) SetLogger(logger *InstanceLogger) ``` -------------------------------- ### NewProxy Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Creates a new Proxy instance with the given options. This is the primary constructor for the Proxy type. ```APIDOC ## NewProxy ### Description Creates a new Proxy instance with the given options. ### Method func NewProxy(opts *Options) (*Proxy, error) ### Parameters * **opts** (*Options): Configuration options for the proxy. ### Response * **(*Proxy, error)**: A pointer to the created Proxy instance and an error if creation failed. ``` -------------------------------- ### Define Proxy Options Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Defines configuration options for the proxy, including address, streaming large bodies, SSL settings, and log file path. ```go type Options struct { Debug int Addr string StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式 SslInsecure bool CaRootPath string NewCaFunc func() (cert.CA, error) //创建 Ca 的函数 Upstream string LogFilePath string // Path to write logs to file } ``` -------------------------------- ### BaseAddon SSEMessage Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for SSEMessage hook. This method does nothing. ```go func (addon *BaseAddon) SSEMessage(*Flow) ``` -------------------------------- ### Log at info level Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a message at the info level using InstanceLogger. ```go func (il *InstanceLogger) Info(args ...interface{}) ``` -------------------------------- ### Log at warn level Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a message at the warn level using InstanceLogger. ```go func (il *InstanceLogger) Warn(args ...interface{}) ``` -------------------------------- ### InstanceLogAddon Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy A specific addon for logging instance-related events. It allows for configuring log output to a file and setting a custom logger. ```APIDOC ## InstanceLogAddon Methods ### NewInstanceLogAddonWithFile Creates a new InstanceLogAddon that logs to a specified file. - **Method**: `NewInstanceLogAddonWithFile` - **Parameters**: - `addr` (string) - Required - The address associated with the addon. - `instanceName` (string) - Required - The name of the instance. - `logFilePath` (string) - Required - The path to the log file. - **Returns**: - `*InstanceLogAddon` - A pointer to the created InstanceLogAddon. ### SetLogger Sets a custom logger for the InstanceLogAddon. - **Method**: `SetLogger` - **Parameters**: - `logger` (*InstanceLogger) - Required - The custom logger to set. ``` -------------------------------- ### BaseAddon TlsEstablishedServer Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for TlsEstablishedServer hook. This method does nothing. ```go func (addon *BaseAddon) TlsEstablishedServer(*ConnContext) ``` -------------------------------- ### NewMapRemoteFromFile Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Constructor for MapRemote, creating a new instance by loading remote mappings from a specified file. Added in v1.6.0. ```go func NewMapRemoteFromFile(filename string) (*MapRemote, error) ``` -------------------------------- ### WebAddon Methods Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Provides methods for handling various stages of a proxy request and response lifecycle, including request/response headers, errors, and WebSocket/SSE events. ```APIDOC ## type WebAddon ### Description Represents a web addon for handling proxy events. ## func (web *WebAddon) Request ### Description Handles incoming requests. ### Signature ```go func (web *WebAddon) Request(f *proxy.Flow) ``` ## func (web *WebAddon) RequestError ### Description Handles errors that occur during request processing. ### Signature ```go func (web *WebAddon) RequestError(f *proxy.Flow, err error) ``` ## func (web *WebAddon) Requestheaders ### Description Handles request headers. ### Signature ```go func (web *WebAddon) Requestheaders(f *proxy.Flow) ``` ## func (web *WebAddon) Response ### Description Handles outgoing responses. ### Signature ```go func (web *WebAddon) Response(f *proxy.Flow) ``` ## func (web *WebAddon) Responseheaders ### Description Handles response headers. ### Signature ```go func (web *WebAddon) Responseheaders(f *proxy.Flow) ``` ## func (web *WebAddon) SSEEnd ### Description Sends a Server-Sent Events (SSE) connection end message. ### Signature ```go func (web *WebAddon) SSEEnd(f *proxy.Flow) ``` ## func (web *WebAddon) SSEMessage ### Description Sends a Server-Sent Events (SSE) message. ### Signature ```go func (web *WebAddon) SSEMessage(f *proxy.Flow) ``` ## func (web *WebAddon) SSEStart ### Description Sends a Server-Sent Events (SSE) connection establishment message. ### Signature ```go func (web *WebAddon) SSEStart(f *proxy.Flow) ``` ## func (web *WebAddon) ServerDisconnected ### Description Handles a server disconnection event. ### Signature ```go func (web *WebAddon) ServerDisconnected(connCtx *proxy.ConnContext) ``` ## func (web *WebAddon) WebSocketEnd ### Description Sends a WebSocket connection end message. ### Signature ```go func (web *WebAddon) WebSocketEnd(f *proxy.Flow) ``` ## func (web *WebAddon) WebSocketMessage ### Description Sends a WebSocket message. ### Signature ```go func (web *WebAddon) WebSocketMessage(f *proxy.Flow) ``` ## func (web *WebAddon) WebSocketStart ### Description Sends a WebSocket connection establishment message. ### Signature ```go func (web *WebAddon) WebSocketStart(f *proxy.Flow) ``` ``` -------------------------------- ### InstanceLogAddon Requestheaders Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when request headers are processed. ```go func (addon *InstanceLogAddon) Requestheaders(f *Flow) ``` -------------------------------- ### BaseAddon WebSocketEnd Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for WebSocketEnd hook. This method does nothing. ```go func (addon *BaseAddon) WebSocketEnd(*Flow) ``` -------------------------------- ### Proxy.SetUpstreamProxy Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Sets a function to determine the upstream proxy for a request. This allows for dynamic upstream proxy configuration. ```APIDOC ## Proxy.SetUpstreamProxy ### Description Sets a function to determine the upstream proxy for a request. ### Method func (proxy *Proxy) SetUpstreamProxy(fn func(req *http.Request) (*url.URL, error)) ### Parameters * **fn** (func(req *http.Request) (*url.URL, error)): A function that takes an http.Request and returns the upstream proxy URL or an error. ### Response None ``` -------------------------------- ### BaseAddon ServerConnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for ServerConnected hook. This method does nothing. ```go func (addon *BaseAddon) ServerConnected(*ConnContext) ``` -------------------------------- ### BaseAddon ClientDisconnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for ClientDisconnected hook. This method does nothing. ```go func (addon *BaseAddon) ClientDisconnected(*ClientConn) ``` -------------------------------- ### Define Proxy struct Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Defines the main Proxy struct, holding options, version, and registered addons. ```go type Proxy struct { Opts *Options Version string Addons []Addon // contains filtered or unexported fields } ``` -------------------------------- ### BaseAddon ClientConnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for ClientConnected hook. This method does nothing. ```go func (addon *BaseAddon) ClientConnected(*ClientConn) ``` -------------------------------- ### Create New UpstreamCertAddon Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Factory function to create a new UpstreamCertAddon. Initializes the addon with the specified upstreamCert setting. ```go func NewUpstreamCertAddon(upstreamCert bool) *UpstreamCertAddon ``` -------------------------------- ### NewMapLocalFromFile Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Creates a new MapLocal addon instance by loading mapping rules from a specified file. ```APIDOC ## NewMapLocalFromFile ### Description Initializes a MapLocal addon from a file, enabling local request mapping. ### Method func NewMapLocalFromFile(filename string) (*MapLocal, error) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response * MapLocal (pointer to MapLocal) - The initialized MapLocal addon. * error - An error if the file cannot be read or parsed. #### Response Example None ``` -------------------------------- ### BaseAddon SSEStart Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for SSEStart hook. This method does nothing. ```go func (addon *BaseAddon) SSEStart(*Flow) ``` -------------------------------- ### BaseAddon ServerDisconnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for ServerDisconnected hook. This method does nothing. ```go func (addon *BaseAddon) ServerDisconnected(*ConnContext) ``` -------------------------------- ### NewWebAddon Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Constructs a new WebAddon instance, which is used to handle web proxying functionalities. It takes an address string as an argument. ```APIDOC ## func NewWebAddon ### Description Constructs a new WebAddon instance, which is used to handle web proxying functionalities. It takes an address string as an argument. ### Signature ```go func NewWebAddon(addr string) *WebAddon ``` ### Parameters #### Path Parameters - **addr** (string) - Required - The address to bind the web addon to. ``` -------------------------------- ### NewSelfSignCA Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/cert Creates a new CA instance by loading from a store path or generating a new one and storing it. Requires a path string. ```go func NewSelfSignCA(path string) (CA, error) ``` -------------------------------- ### BaseAddon Struct Definition Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Provides a default, empty implementation for the Addon interface. Useful for creating addons that only need to handle specific events. ```go type BaseAddon struct{} ``` -------------------------------- ### Struct from File Loading Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Loads configuration or data from a file into a Go struct. Handles file parsing and unmarshalling. ```go func NewStructFromFile(filename string, v interface{}) error ``` -------------------------------- ### Log formatted message at info level Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a formatted message at the info level using InstanceLogger. ```go func (il *InstanceLogger) Infof(format string, args ...interface{}) ``` -------------------------------- ### Handle Client Connection in UpstreamCertAddon Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function executed when a client connects. This method is part of the addon's lifecycle for managing client connections. ```go func (addon *UpstreamCertAddon) ClientConnected(conn *ClientConn) ``` -------------------------------- ### InstanceLogger Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Provides methods for logging within a specific proxy instance. It supports different log levels and allows for structured logging with fields. ```APIDOC ## InstanceLogger Methods ### NewInstanceLogger Creates a new instance logger. - **Method**: `NewInstanceLogger` - **Parameters**: - `addr` (string) - Required - The address associated with the logger. - `instanceName` (string) - Required - The name of the instance. - **Returns**: - `*InstanceLogger` - A pointer to the created InstanceLogger. ### NewInstanceLoggerWithFile Creates a new instance logger that writes to a file. - **Method**: `NewInstanceLoggerWithFile` - **Parameters**: - `addr` (string) - Required - The address associated with the logger. - `instanceName` (string) - Required - The name of the instance. - `logFilePath` (string) - Required - The path to the log file. - **Returns**: - `*InstanceLogger` - A pointer to the created InstanceLogger. ### Debug Logs a debug message. - **Method**: `Debug` - **Parameters**: - `args` ([]interface{}) - Required - The arguments to log. ### Debugf Logs a debug message with formatting. - **Method**: `Debugf` - **Parameters**: - `format` (string) - Required - The format string. - `args` ([]interface{}) - Required - The arguments for formatting. ### Info Logs an informational message. - **Method**: `Info` - **Parameters**: - `args` ([]interface{}) - Required - The arguments to log. ### Infof Logs an informational message with formatting. - **Method**: `Infof` - **Parameters**: - `format` (string) - Required - The format string. - `args` ([]interface{}) - Required - The arguments for formatting. ### Warn Logs a warning message. - **Method**: `Warn` - **Parameters**: - `args` ([]interface{}) - Required - The arguments to log. ### Warnf Logs a warning message with formatting. - **Method**: `Warnf` - **Parameters**: - `format` (string) - Required - The format string. - `args` ([]interface{}) - Required - The arguments for formatting. ### Error Logs an error message. - **Method**: `Error` - **Parameters**: - `args` ([]interface{}) - Required - The arguments to log. ### Errorf Logs an error message with formatting. - **Method**: `Errorf` - **Parameters**: - `format` (string) - Required - The format string. - `args` ([]interface{}) - Required - The arguments for formatting. ### Fatal Logs a fatal error message and exits. - **Method**: `Fatal` - **Parameters**: - `args` ([]interface{}) - Required - The arguments to log. ### Fatalf Logs a fatal error message with formatting and exits. - **Method**: `Fatalf` - **Parameters**: - `format` (string) - Required - The format string. - `args` ([]interface{}) - Required - The arguments for formatting. ### GetEntry Retrieves the underlying log entry. - **Method**: `GetEntry` - **Returns**: - `*log.Entry` - The log entry. ### WithFields Adds structured fields to the logger. - **Method**: `WithFields` - **Parameters**: - `fields` (log.Fields) - Required - The fields to add. - **Returns**: - `*log.Entry` - A new logger entry with the added fields. ``` -------------------------------- ### Log formatted message at warn level Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a formatted message at the warn level using InstanceLogger. ```go func (il *InstanceLogger) Warnf(format string, args ...interface{}) ``` -------------------------------- ### InstanceLogger Fatalf Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a formatted message at the fatal level. ```go func (il *InstanceLogger) Fatalf(format string, args ...interface{}) ``` -------------------------------- ### WebAddon Request Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Handles incoming requests. This method is called for each request processed by the proxy. ```go func (web *WebAddon) Request(f *proxy.Flow) ``` -------------------------------- ### Proxy.AddAddon Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Adds an addon to the proxy. This method allows extending the proxy's functionality by registering custom addons. ```APIDOC ## Proxy.AddAddon ### Description Adds an addon to the proxy. ### Method func (proxy *Proxy) AddAddon(addon Addon) ### Parameters * **addon** (Addon): The addon to be added to the proxy. ### Response None ``` -------------------------------- ### Go-Mitmproxy Addon Interface Definition Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy Defines the interface for creating custom addons in Go-Mitmproxy. Implement these methods to hook into various proxy events. ```go 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 // WebSocket connection established WebSocketStart(*Flow) // WebSocket message received WebSocketMessage(*Flow) // WebSocket connection closed WebSocketEnd(*Flow) // SSE connection established SSEStart(*Flow) // SSE message received SSEMessage(*Flow) // SSE connection closed SSEEnd(*Flow) // HTTP request failed with error RequestError(*Flow, error) // HTTP CONNECT request failed with error HTTPConnectError(*Flow, error) } ``` -------------------------------- ### BaseAddon WebSocketMessage Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for WebSocketMessage hook. This method does nothing. ```go func (addon *BaseAddon) WebSocketMessage(*Flow) ``` -------------------------------- ### DummyCert Method for SelfSignCA Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/cert Generates a dummy TLS certificate for a given common name. This method is marked with a TODO regarding support for multiple SubjectAltName. ```go func (ca *SelfSignCA) DummyCert(commonName string) (*tls.Certificate, error) ``` -------------------------------- ### InstanceLogAddon HTTPConnectError Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when an HTTP connect error occurs. ```go func (addon *InstanceLogAddon) HTTPConnectError(f *Flow, err error) ``` -------------------------------- ### InstanceLogger Errorf Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a formatted message at the error level. ```go func (il *InstanceLogger) Errorf(format string, args ...interface{}) ``` -------------------------------- ### Define InstanceLogger Structure Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Defines the InstanceLogger structure for logging with instance identification. ```go type InstanceLogger struct { InstanceID string InstanceName string Port string LogFilePath string // contains filtered or unexported fields } ``` -------------------------------- ### InstanceLogAddon RequestError Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a request error occurs. ```go func (addon *InstanceLogAddon) RequestError(f *Flow, err error) ``` -------------------------------- ### NewMapLocalFromFile Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Constructor for MapLocal, creating a new instance by loading mappings from a specified file. Added in v1.6.0. ```go func NewMapLocalFromFile(filename string) (*MapLocal, error) ``` -------------------------------- ### NewSelfSignCA Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/cert Loads a CA from a store path or creates a new CA and stores it. This function is used to initialize a CA instance that persists its configuration. ```APIDOC ## func NewSelfSignCA ### Description Loads a CA from a store path or creates a new CA then stores it. ### Signature ```go func NewSelfSignCA(path string) (CA, error) ``` ### Parameters #### Path Parameters - **path** (string) - The file path to the CA store. ``` -------------------------------- ### WebAddon SSEStart Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Sends a message indicating the establishment of an SSE connection. This method was added in v1.8.10. ```go func (web *WebAddon) SSEStart(f *proxy.Flow) ``` -------------------------------- ### BaseAddon RequestError Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for RequestError hook. This method does nothing. ```go func (addon *BaseAddon) RequestError(*Flow, error) ``` -------------------------------- ### TLS Key Log Writer Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Provides an io.Writer for TLS key logging. Essential for debugging TLS traffic. ```go func GetTlsKeyLogWriter() io.Writer ``` -------------------------------- ### InstanceLogger Debugf Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a formatted message at the debug level. ```go func (il *InstanceLogger) Debugf(format string, args ...interface{}) ``` -------------------------------- ### Handle response Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function for processing responses. ```go func (addon *LogAddon) Response(f *Flow) ``` -------------------------------- ### Define Request struct Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Represents an HTTP request, including method, URL, headers, and body. ```go type Request struct { Method string URL *url.URL Proto string Header http.Header Body []byte // contains filtered or unexported fields } ``` -------------------------------- ### NewSelfSignCAMemory Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/cert Creates a new CA instance that resides only in memory. This CA will be reset when the process restarts. It does not require any arguments. ```go func NewSelfSignCAMemory() (CA, error) ``` -------------------------------- ### ServerConn Methods Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Provides methods for interacting with server connection objects, including JSON marshaling and TLS state retrieval. ```APIDOC ## ServerConn Methods ### MarshalJSON Marshals the server connection object into JSON format. ### TlsState Retrieves the TLS connection state for the server connection. ``` -------------------------------- ### InstanceLogger Error Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a message at the error level. ```go func (il *InstanceLogger) Error(args ...interface{}) ``` -------------------------------- ### Handle HTTP connect error Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function for HTTP connect errors. ```go func (addon *LogAddon) HTTPConnectError(f *Flow, err error) ``` -------------------------------- ### NewDumperWithFilename Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Constructor for the Dumper struct, creating a new Dumper instance that writes to a specified file with a given logging level. Added in v1.0.0. ```go func NewDumperWithFilename(filename string, level int) *Dumper ``` -------------------------------- ### Handle server disconnection Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function for when a server disconnects. ```go func (addon *LogAddon) ServerDisconnected(connCtx *ConnContext) ``` -------------------------------- ### NewDumperWithFilename Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Creates a new Dumper instance that writes to a file specified by filename with a given level of detail. ```APIDOC ## NewDumperWithFilename ### Description Initializes a new Dumper addon that writes to a specified file. ### Method func NewDumperWithFilename(filename string, level int) *Dumper ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response * Dumper (pointer to Dumper) - A new Dumper instance. #### Response Example None ``` -------------------------------- ### Set authentication proxy function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Sets a custom function to handle proxy authentication. ```go func (proxy *Proxy) SetAuthProxy(fn func(res http.ResponseWriter, req *http.Request) (bool, error)) ``` -------------------------------- ### Define LogAddon struct Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Defines the LogAddon struct, which logs connection and flow information. ```go type LogAddon struct { BaseAddon } ``` -------------------------------- ### Handle request headers Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function for processing request headers. ```go func (addon *LogAddon) Requestheaders(f *Flow) ``` -------------------------------- ### Canonical Address Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Returns the URL's host with a port suffix. Useful for ensuring consistent address formatting. ```go func CanonicalAddr(url *url.URL) string ``` -------------------------------- ### InstanceLogger Debug Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a message at the debug level. ```go func (il *InstanceLogger) Debug(args ...interface{}) ``` -------------------------------- ### WebAddon Responseheaders Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Handles response headers. This method is called before the response body is processed. ```go func (web *WebAddon) Responseheaders(f *proxy.Flow) ``` -------------------------------- ### Define ConnContext Structure Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Defines the connection context structure, including client and server connections, and an intercept flag for HTTPS parsing. ```go type ConnContext struct { ClientConn *ClientConn `json:"clientConn"` ServerConn *ServerConn `json:"serverConn"` Intercept bool `json:"intercept"` // Indicates whether to parse HTTPS FlowCount atomic.Uint32 `json:"-"` // Number of HTTP requests made on the same connection // contains filtered or unexported fields } ``` -------------------------------- ### InstanceLogAddon ServerDisconnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a server disconnects. ```go func (addon *InstanceLogAddon) ServerDisconnected(connCtx *ConnContext) ``` -------------------------------- ### InstanceLogAddon ClientDisconnected Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function invoked when a client disconnects. ```go func (addon *InstanceLogAddon) ClientDisconnected(client *ClientConn) ``` -------------------------------- ### NewUpstreamCertAddon Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Creates a new UpstreamCertAddon with the specified upstreamCert setting. ```APIDOC ## NewUpstreamCertAddon ### Description Creates a new UpstreamCertAddon with the specified upstreamCert setting. ### Method ```go func NewUpstreamCertAddon(upstreamCert bool) *UpstreamCertAddon ``` ``` -------------------------------- ### Handle client disconnection Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Callback function for when a client disconnects. ```go func (addon *LogAddon) ClientDisconnected(client *ClientConn) ``` -------------------------------- ### InstanceLogger Fatal Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a message at the fatal level. ```go func (il *InstanceLogger) Fatal(args ...interface{}) ``` -------------------------------- ### Host Matching Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Checks if a given address matches any host in a list of hosts. Useful for routing or access control. ```go func MatchHost(address string, hosts []string) bool ``` -------------------------------- ### LogAddon.ServerConnected Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs when a server connects. This method is part of the LogAddon type and is called when a new server connection is established. ```APIDOC ## LogAddon.ServerConnected ### Description Logs when a server connects. ### Method func (addon *LogAddon) ServerConnected(connCtx *ConnContext) ### Parameters * **connCtx** (*ConnContext): Information about the server connection context. ### Response None ``` -------------------------------- ### NewDumper Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Creates a new Dumper instance that writes to a specified io.Writer with a given level of detail. ```APIDOC ## NewDumper ### Description Initializes a new Dumper addon that writes to an io.Writer. ### Method func NewDumper(out io.Writer, level int) *Dumper ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response * Dumper (pointer to Dumper) - A new Dumper instance. #### Response Example None ``` -------------------------------- ### LogAddon.SSEEnd Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs the end of an SSE stream. This method is part of the LogAddon type. ```APIDOC ## LogAddon.SSEEnd ### Description Logs the end of an SSE stream. ### Method func (addon *LogAddon) SSEEnd(f *Flow) ### Parameters * **f** (*Flow): The flow associated with the SSE stream. ### Response None ``` -------------------------------- ### LogAddon.SSEMessage Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs an SSE message. This method is part of the LogAddon type. ```APIDOC ## LogAddon.SSEMessage ### Description Logs an SSE message. ### Method func (addon *LogAddon) SSEMessage(f *Flow) ### Parameters * **f** (*Flow): The flow associated with the SSE message. ### Response None ``` -------------------------------- ### WebAddon Requestheaders Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Handles request headers. This method is called before the request body is processed. ```go func (web *WebAddon) Requestheaders(f *proxy.Flow) ``` -------------------------------- ### ClientConn MarshalJSON Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Custom JSON marshaling for the ClientConn struct. ```go func (c *ClientConn) MarshalJSON() ([]byte, error) ``` -------------------------------- ### Proxy Connection Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Establishes a network connection through a proxy. Used for dialing connections in proxy scenarios. ```go func GetProxyConn(ctx context.Context, proxyUrl *url.URL, address string, sslInsecure bool) (net.Conn, error) ``` -------------------------------- ### BaseAddon HTTPConnectError Method Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Default implementation for HTTPConnectError hook. This method does nothing. ```go func (addon *BaseAddon) HTTPConnectError(*Flow, error) ``` -------------------------------- ### WebAddon Struct Definition Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Defines the WebAddon struct, which embeds proxy.BaseAddon. It is used for handling web-related proxy events. ```go type WebAddon struct { proxy.BaseAddon // contains filtered or unexported fields } ``` -------------------------------- ### NewDumper Function Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/addon Constructor for the Dumper struct, creating a new Dumper instance with a specified output writer and logging level. ```go func NewDumper(out io.Writer, level int) *Dumper ``` -------------------------------- ### WebAddon SSEMessage Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Sends a Server-Sent Events (SSE) message. This method was added in v1.8.10. ```go func (web *WebAddon) SSEMessage(f *proxy.Flow) ``` -------------------------------- ### Shutdown the proxy Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Shuts down the proxy gracefully with a context. ```go func (proxy *Proxy) Shutdown(ctx context.Context) error ``` -------------------------------- ### Addon Interface Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy The Addon interface defines the methods that can be implemented to customize mitmproxy's behavior. These methods are called at various points in the proxy's operation, allowing for interception and modification of traffic. ```APIDOC ## Addon Interface ### Description The `Addon` interface provides a set of callback methods that are invoked during different stages of the mitmproxy lifecycle. By implementing these methods, users can create custom logic to inspect, modify, or react to network traffic. ### Methods - **ClientConnected(*ClientConn)**: Called when a client connects to mitmproxy. - **ClientDisconnected(*ClientConn)**: Called when a client connection is closed. - **ServerConnected(*ConnContext)**: Called when mitmproxy connects to a server. - **ServerDisconnected(*ConnContext)**: Called when a server connection is closed. - **TlsEstablishedServer(*ConnContext)**: Called after a successful TLS handshake with a server. - **Requestheaders(*Flow)**: Called when HTTP request headers are received. - **Request(*Flow)**: Called when the full HTTP request is received. - **Responseheaders(*Flow)**: Called when HTTP response headers are received. - **Response(*Flow)**: Called when the full HTTP response is received. - **StreamRequestModifier(*Flow, io.Reader) io.Reader**: Allows modification of the request body stream. - **StreamResponseModifier(*Flow, io.Reader) io.Reader**: Allows modification of the response body stream. - **AccessProxyServer(req *http.Request, res http.ResponseWriter)**: Hook for accessing the proxy server request and response. - **WebSocketStart(*Flow)**: Called when a WebSocket connection starts. - **WebSocketMessage(*Flow)**: Called when a WebSocket message is received or sent. - **WebSocketEnd(*Flow)**: Called when a WebSocket connection ends. - **SSEStart(*Flow)**: Called when an SSE stream starts. - **SSEMessage(*Flow)**: Called for each SSE event received. - **SSEEnd(*Flow)**: Called when an SSE stream ends. - **RequestError(*Flow, error)**: Called when an HTTP request fails. - **HTTPConnectError(*Flow, error)**: Called when an HTTP CONNECT request fails. ``` -------------------------------- ### Response Check Wrapper Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Creates a ResponseWriter that allows checking if a response has been written. Useful for intercepting or modifying responses. ```go func NewResponseCheck(r http.ResponseWriter) http.ResponseWriter ``` -------------------------------- ### Log WebSocket connection end Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs the end of a WebSocket connection. ```go func (addon *LogAddon) WebSocketEnd(f *Flow) ``` -------------------------------- ### WebAddon Response Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Handles outgoing responses. This method is called for each response processed by the proxy. ```go func (web *WebAddon) Response(f *proxy.Flow) ``` -------------------------------- ### WebSocket Detection Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Determines if a byte buffer represents a WebSocket connection initiation. ```go func IsWebSocket(buf []byte) bool ``` -------------------------------- ### InstanceLogger.Info Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Info logs at the info level. This method is part of the InstanceLogger type and is used for logging informational messages. ```APIDOC ## InstanceLogger.Info ### Description Info logs at info level. ### Method func (il *InstanceLogger) Info(args ...interface{}) ### Parameters * **args** (...interface{}): Variable arguments to be logged at info level. ### Response None ``` -------------------------------- ### LogAddon.ClientConnected Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs when a client connects. This method is part of the LogAddon type and is called when a new client connection is established. ```APIDOC ## LogAddon.ClientConnected ### Description Logs when a client connects. ### Method func (addon *LogAddon) ClientConnected(client *ClientConn) ### Parameters * **client** (*ClientConn): Information about the connected client. ### Response None ``` -------------------------------- ### Log SSE message Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a Server-Sent Events (SSE) message. ```go func (addon *LogAddon) SSEMessage(f *Flow) ``` -------------------------------- ### Close the proxy Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Closes the proxy instance, releasing resources. ```go func (proxy *Proxy) Close() error ``` -------------------------------- ### CA Interface Definition Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/cert Defines the CA interface with methods to retrieve the root certificate and generate certificates for a given common name. ```go type CA interface { GetRootCA() *x509.Certificate GetCert(commonName string) (*tls.Certificate, error) } ``` -------------------------------- ### WebAddon SSEEnd Handler Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/web Sends a message indicating the end of an SSE connection. This method was added in v1.8.10. ```go func (web *WebAddon) SSEEnd(f *proxy.Flow) ``` -------------------------------- ### ClientConn Struct Definition Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Represents a client connection to mitmproxy, including connection details and TLS information. ```go type ClientConn struct { Id uuid.UUID Conn net.Conn Tls bool NegotiatedProtocol string UpstreamCert bool // Connect to upstream server to look up certificate details. Default: True // contains filtered or unexported fields } ``` -------------------------------- ### Response Methods Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Provides methods for interacting with and checking the properties of a Response object. ```APIDOC ## Response Methods ### DecodedBody Retrieves the decoded body of the response. ### IsTextContentType Checks if the response content type is a text-based type. ### ReplaceToDecodedBody Replaces the response body with its decoded version. ``` -------------------------------- ### NewSelfSignCAMemory Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/cert Creates a new CA that resides only in memory. This CA instance will be reset when the process restarts, making it suitable for temporary or volatile operations. ```APIDOC ## func NewSelfSignCAMemory ### Description Creates a new CA that only lives in memory. It will change when the process restarts. ### Signature ```go func NewSelfSignCAMemory() (CA, error) ``` ### Parameters This function does not accept any parameters. ``` -------------------------------- ### Log WebSocket message Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Logs a WebSocket message. ```go func (addon *LogAddon) WebSocketMessage(f *Flow) ``` -------------------------------- ### Reader to Buffer Conversion Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/internal/helper Reads data from an io.Reader into a byte buffer up to a specified limit. Returns the buffer and a new reader if the limit is not reached, or nil and the original reader if the limit is exceeded. ```go func ReaderToBuffer(r io.Reader, limit int64) ([]byte, io.Reader, error) ``` -------------------------------- ### InstanceLogger.Warnf Source: https://pkg.go.dev/github.com/lqqyt2423/go-mitmproxy/proxy Warnf logs formatted messages at the warn level. This method is part of the InstanceLogger type and allows for formatted warning logging. ```APIDOC ## InstanceLogger.Warnf ### Description Warnf logs formatted at warn level. ### Method func (il *InstanceLogger) Warnf(format string, args ...interface{}) ### Parameters * **format** (string): The format string for the log message. * **args** (...interface{}): Variable arguments to be formatted into the log message. ### Response None ```