Documentation
¶
Index ¶
- Constants
- func IsErrorType(err error, typ ErrorType) bool
- func New(certPath, keyPath string, logger *slog.Logger) (*http.Server, error)
- type ContentModifierInterceptor
- func (cmi *ContentModifierInterceptor) AddBodyReplacement(search, replace string)
- func (cmi *ContentModifierInterceptor) AddRequestHeaderModification(header, value string)
- func (cmi *ContentModifierInterceptor) AddResponseHeaderModification(header, value string)
- func (cmi *ContentModifierInterceptor) ProcessRequest(req *http.Request) (*http.Request, bool, error)
- func (cmi *ContentModifierInterceptor) ProcessResponse(resp *http.Response, req *http.Request) (*http.Response, error)
- type ErrorType
- type FilteringInterceptor
- func (fi *FilteringInterceptor) AddBlockedHost(host string)
- func (fi *FilteringInterceptor) AddBlockedPath(path string)
- func (fi *FilteringInterceptor) AddBlockedUserAgent(userAgent string)
- func (fi *FilteringInterceptor) ProcessRequest(req *http.Request) (*http.Request, bool, error)
- func (fi *FilteringInterceptor) ProcessResponse(resp *http.Response, req *http.Request) (*http.Response, error)
- func (fi *FilteringInterceptor) SetBlockResponse(status int, message, body string)
- type HTTPClient
- type HTTPInterceptor
- type InspectingHTTPClient
- type LoggingInterceptor
- type ProxyError
- type RequestCreator
- type RequestIDInterceptor
- func (ri *RequestIDInterceptor) GetRequestByID(id string) *http.Request
- func (ri *RequestIDInterceptor) GetResponseByID(id string) *http.Response
- func (ri *RequestIDInterceptor) ProcessRequest(req *http.Request) (*http.Request, bool, error)
- func (ri *RequestIDInterceptor) ProcessResponse(resp *http.Response, req *http.Request) (*http.Response, error)
- type ServerMux
- type TLSHandshaker
Constants ¶
const ( DefaultReadTimeout = 30 * time.Second DefaultWriteTimeout = 30 * time.Second DefaultIdleTimeout = 90 * time.Second )
Default timeout values
Variables ¶
This section is empty.
Functions ¶
func IsErrorType ¶
IsErrorType determines if the specified error is a ProxyError with a specific ErrorType
Types ¶
type ContentModifierInterceptor ¶
type ContentModifierInterceptor struct {
// contains filtered or unexported fields
}
ContentModifierInterceptor is an interceptor that modifies the contents of requests and responses
func NewContentModifierInterceptor ¶
func NewContentModifierInterceptor(logger *slog.Logger) *ContentModifierInterceptor
NewContentModifierInterceptor creates a new ContentModifierInterceptor
func (*ContentModifierInterceptor) AddBodyReplacement ¶
func (cmi *ContentModifierInterceptor) AddBodyReplacement(search, replace string)
AddBodyReplacement adds a response body replacement
func (*ContentModifierInterceptor) AddRequestHeaderModification ¶
func (cmi *ContentModifierInterceptor) AddRequestHeaderModification(header, value string)
AddRequestHeaderModification adds a request header modification
func (*ContentModifierInterceptor) AddResponseHeaderModification ¶
func (cmi *ContentModifierInterceptor) AddResponseHeaderModification(header, value string)
AddResponseHeaderModification adds a response header modification
func (*ContentModifierInterceptor) ProcessRequest ¶
func (cmi *ContentModifierInterceptor) ProcessRequest(req *http.Request) (*http.Request, bool, error)
ProcessRequest modifies the contents of a request
func (*ContentModifierInterceptor) ProcessResponse ¶
func (cmi *ContentModifierInterceptor) ProcessResponse(resp *http.Response, req *http.Request) (*http.Response, error)
ProcessResponse modifies the contents of a response
type ErrorType ¶
type ErrorType string
ErrorType represents the type of proxy error
const ( // ErrHijack is an error that occurs when HTTP connection hijacking fails ErrHijack ErrorType = "hijack" // ErrTLSHandshake is an error that occurs when TLS handshake fails ErrTLSHandshake ErrorType = "tls_handshake" // ErrCreateRequest is an error that occurs when request creation fails ErrCreateRequest ErrorType = "create_request" // ErrSendRequest is an error that occurs when request sending fails ErrSendRequest ErrorType = "send_request" // ErrCertificate is an error that occurs when certificate-related processing fails ErrCertificate ErrorType = "certificate" // ErrGateway is an error that occurs when the proxy cannot reach the upstream server (502 Bad Gateway) ErrGateway ErrorType = "gateway" // ErrTimeout is an error that occurs when the upstream server doesn't respond in time (504 Gateway Timeout) ErrTimeout ErrorType = "timeout" )
type FilteringInterceptor ¶
type FilteringInterceptor struct {
// contains filtered or unexported fields
}
FilteringInterceptor is an interceptor that filters requests
func NewFilteringInterceptor ¶
func NewFilteringInterceptor(logger *slog.Logger) *FilteringInterceptor
NewFilteringInterceptor creates a new FilteringInterceptor
func (*FilteringInterceptor) AddBlockedHost ¶
func (fi *FilteringInterceptor) AddBlockedHost(host string)
AddBlockedHost adds a hostname to block
func (*FilteringInterceptor) AddBlockedPath ¶
func (fi *FilteringInterceptor) AddBlockedPath(path string)
AddBlockedPath adds a URL path to block
func (*FilteringInterceptor) AddBlockedUserAgent ¶
func (fi *FilteringInterceptor) AddBlockedUserAgent(userAgent string)
AddBlockedUserAgent adds a user agent to block
func (*FilteringInterceptor) ProcessRequest ¶
ProcessRequest filters requests
func (*FilteringInterceptor) ProcessResponse ¶
func (fi *FilteringInterceptor) ProcessResponse(resp *http.Response, req *http.Request) (*http.Response, error)
ProcessResponse processes responses Returns custom response if the request was blocked in request processing
func (*FilteringInterceptor) SetBlockResponse ¶
func (fi *FilteringInterceptor) SetBlockResponse(status int, message, body string)
SetBlockResponse is used to set a custom response for blocked requests
type HTTPClient ¶
HTTPClient is an interface for making HTTP requests
type HTTPInterceptor ¶
type HTTPInterceptor interface {
// Request processing - returns the modified request
// Returning an error will stop the processing
// Returning true will skip subsequent interceptors (termination)
ProcessRequest(*http.Request) (*http.Request, bool, error)
// Response processing - returns the modified response
// Can also access the related request
// Returning an error will stop the processing
ProcessResponse(*http.Response, *http.Request) (*http.Response, error)
}
HTTPInterceptor is a basic interface that can process both requests and responses
type InspectingHTTPClient ¶
type InspectingHTTPClient struct {
Client HTTPClient
RequestLog []string
ResponseLog []string
BodyLog []string
}
InspectingHTTPClient is an HTTPClient that records HTTP requests and responses
func NewInspectingHTTPClient ¶
func NewInspectingHTTPClient(client HTTPClient) *InspectingHTTPClient
NewInspectingHTTPClient creates a new InspectingHTTPClient
type LoggingInterceptor ¶
type LoggingInterceptor struct {
// contains filtered or unexported fields
}
LoggingInterceptor is an interceptor that logs the contents of requests and responses
func NewLoggingInterceptor ¶
func NewLoggingInterceptor(logger *slog.Logger) *LoggingInterceptor
NewLoggingInterceptor creates a new LoggingInterceptor
func (*LoggingInterceptor) ProcessRequest ¶
ProcessRequest logs the contents of a request
func (*LoggingInterceptor) ProcessResponse ¶
func (li *LoggingInterceptor) ProcessResponse(resp *http.Response, req *http.Request) (*http.Response, error)
ProcessResponse logs the contents of a response
type ProxyError ¶
type ProxyError struct {
Type ErrorType // Type of error
Op string // Operation where the error occurred
Message string // Error message
Err error // Original error
}
ProxyError represents an error that occurs during proxy processing
func GetProxyError ¶
func GetProxyError(err error) *ProxyError
GetProxyError retrieves a ProxyError from an error Returns nil if not a ProxyError
func NewProxyError ¶
func NewProxyError(typ ErrorType, op string, message string, err error) *ProxyError
NewProxyError creates a new ProxyError
func (*ProxyError) Is ¶
func (e *ProxyError) Is(target error) bool
Is is a method used for errors.Is It allows comparison with ProxyErrors that have the same error type
type RequestCreator ¶
RequestCreator is an interface for creating requests
type RequestIDInterceptor ¶
type RequestIDInterceptor struct {
// contains filtered or unexported fields
}
RequestIDInterceptor is an interceptor that generates and tracks request IDs
func NewRequestIDInterceptor ¶
func NewRequestIDInterceptor(logger *slog.Logger) *RequestIDInterceptor
NewRequestIDInterceptor creates a new RequestIDInterceptor
func (*RequestIDInterceptor) GetRequestByID ¶
func (ri *RequestIDInterceptor) GetRequestByID(id string) *http.Request
Gets the request with the specified ID
func (*RequestIDInterceptor) GetResponseByID ¶
func (ri *RequestIDInterceptor) GetResponseByID(id string) *http.Response
Gets the response with the specified ID
func (*RequestIDInterceptor) ProcessRequest ¶
ProcessRequest assigns an ID to a request
func (*RequestIDInterceptor) ProcessResponse ¶
func (ri *RequestIDInterceptor) ProcessResponse(resp *http.Response, req *http.Request) (*http.Response, error)
ProcessResponse processes responses and associates request IDs
type ServerMux ¶
type ServerMux struct {
// contains filtered or unexported fields
}
func CreateMitmProxy ¶
CreateMitmProxy load pem, and then it return MitmProxy
func (*ServerMux) AddInterceptor ¶
func (mp *ServerMux) AddInterceptor(interceptor HTTPInterceptor)
AddInterceptor adds an interceptor to the list
func (*ServerMux) CreateRequest ¶
CreateRequest implements the RequestCreator interface