Documentation
¶
Overview ¶
Package martian provides an HTTP/1.1 proxy with an API for configurable request and response modifiers.
Index ¶
- type Context
- type MultiError
- type Proxy
- func (p *Proxy) Close()
- func (p *Proxy) Closing() bool
- func (p *Proxy) GetRoundTripper() http.RoundTripper
- func (p *Proxy) Handler() http.Handler
- func (p *Proxy) Serve(l net.Listener) error
- func (p *Proxy) SetDialContext(dial func(context.Context, string, string) (net.Conn, error))
- func (p *Proxy) SetMITM(config *mitm.Config)
- func (p *Proxy) SetRequestModifier(reqmod RequestModifier)
- func (p *Proxy) SetResponseModifier(resmod ResponseModifier)
- func (p *Proxy) SetRoundTripper(rt http.RoundTripper)
- func (p *Proxy) SetUpstreamProxy(proxyURL *url.URL)
- func (p *Proxy) SetUpstreamProxyFunc(f func(*http.Request) (*url.URL, error))
- type RequestModifier
- type RequestModifierFunc
- type RequestResponseModifier
- type ResponseModifier
- type ResponseModifierFunc
- type Session
- func (s *Session) Get(key string) (any, bool)
- func (s *Session) Hijack() (conn net.Conn, brw *bufio.ReadWriter, err error)
- func (s *Session) HijackResponseWriter() (http.ResponseWriter, error)
- func (s *Session) Hijacked() bool
- func (s *Session) IsSecure() bool
- func (s *Session) MarkInsecure()
- func (s *Session) MarkSecure()
- func (s *Session) Set(key string, val any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context provides information and storage for a single request/response pair. Contexts are linked to shared session that is used for multiple requests on a single connection.
func FromContext ¶
func NewContext ¶
NewContext returns a context for the in-flight HTTP request.
func TestContext ¶
TestContext builds a new session and associated context and returns the context. Intended for tests only.
func (*Context) Set ¶
Set takes a key and associates it with val in the context. The value is persisted for the duration of the request and is removed on the following request.
func (*Context) SkipRoundTrip ¶
func (ctx *Context) SkipRoundTrip()
SkipRoundTrip skips the round trip for the current request.
func (*Context) SkippingRoundTrip ¶
SkippingRoundTrip returns whether the current round trip will be skipped.
type MultiError ¶
type MultiError struct {
// contains filtered or unexported fields
}
MultiError is a collection of errors that implements the error interface.
func (*MultiError) Add ¶
func (merr *MultiError) Add(err error)
Add appends an error to the error collection.
func (*MultiError) Empty ¶
func (merr *MultiError) Empty() bool
Empty returns whether the *MultiError contains any errors.
func (*MultiError) Error ¶
func (merr *MultiError) Error() string
Error returns the list of errors separated by newlines.
func (*MultiError) Errors ¶
func (merr *MultiError) Errors() []error
Errors returns the error slice containing the error collection.
type Proxy ¶
type Proxy struct { // AllowHTTP disables automatic HTTP to HTTPS upgrades when the listener is TLS. AllowHTTP bool // ConnectPassthrough passes CONNECT requests to the RoundTripper, // and uses the response body as the connection. ConnectPassthrough bool // WithoutWarning disables the warning header added to requests and responses when modifier errors occur. WithoutWarning bool // ErrorResponse specifies a custom error HTTP response to send when a proxying error occurs. ErrorResponse func(req *http.Request, err error) *http.Response // ReadTimeout is the maximum duration for reading the entire // request, including the body. A zero or negative value means // there will be no timeout. // // Because ReadTimeout does not let Handlers make per-request // decisions on each request body's acceptable deadline or // upload rate, most users will prefer to use // ReadHeaderTimeout. It is valid to use them both. ReadTimeout time.Duration // ReadHeaderTimeout is the amount of time allowed to read // request headers. The connection's read deadline is reset // after reading the headers and the Handler can decide what // is considered too slow for the body. If ReadHeaderTimeout // is zero, the value of ReadTimeout is used. If both are // zero, there is no timeout. ReadHeaderTimeout time.Duration // WriteTimeout is the maximum duration before timing out // writes of the response. It is reset whenever a new // request's header is read. Like ReadTimeout, it does not // let Handlers make decisions on a per-request basis. // A zero or negative value means there will be no timeout. WriteTimeout time.Duration // CloseAfterReply closes the connection after the response has been sent. CloseAfterReply bool // contains filtered or unexported fields }
Proxy is an HTTP proxy with support for TLS MITM and customizable behavior.
func (*Proxy) Close ¶
func (p *Proxy) Close()
Close sets the proxy to the closing state so it stops receiving new connections, finishes processing any inflight requests, and closes existing connections without reading anymore requests from them.
func (*Proxy) GetRoundTripper ¶
func (p *Proxy) GetRoundTripper() http.RoundTripper
GetRoundTripper gets the http.RoundTripper of the proxy.
func (*Proxy) SetDialContext ¶
SetDialContext sets the dial func used to establish a connection.
func (*Proxy) SetRequestModifier ¶
func (p *Proxy) SetRequestModifier(reqmod RequestModifier)
SetRequestModifier sets the request modifier.
func (*Proxy) SetResponseModifier ¶
func (p *Proxy) SetResponseModifier(resmod ResponseModifier)
SetResponseModifier sets the response modifier.
func (*Proxy) SetRoundTripper ¶
func (p *Proxy) SetRoundTripper(rt http.RoundTripper)
SetRoundTripper sets the http.RoundTripper of the proxy.
func (*Proxy) SetUpstreamProxy ¶
SetUpstreamProxy sets the proxy that receives requests from this proxy.
type RequestModifier ¶
type RequestModifier interface { // ModifyRequest modifies the request. ModifyRequest(req *http.Request) error }
RequestModifier is an interface that defines a request modifier that can be used by a proxy.
type RequestModifierFunc ¶
RequestModifierFunc is an adapter for using a function with the given signature as a RequestModifier.
func (RequestModifierFunc) ModifyRequest ¶
func (f RequestModifierFunc) ModifyRequest(req *http.Request) error
ModifyRequest modifies the request using the given function.
type RequestResponseModifier ¶
type RequestResponseModifier interface { RequestModifier ResponseModifier }
RequestResponseModifier is an interface that is both a ResponseModifier and a RequestModifier.
func Noop ¶
func Noop(id string) RequestResponseModifier
Noop returns a modifier that does not change the request or the response.
type ResponseModifier ¶
type ResponseModifier interface { // ModifyResponse modifies the response. ModifyResponse(res *http.Response) error }
ResponseModifier is an interface that defines a response modifier that can be used by a proxy.
type ResponseModifierFunc ¶
ResponseModifierFunc is an adapter for using a function with the given signature as a ResponseModifier.
func (ResponseModifierFunc) ModifyResponse ¶
func (f ResponseModifierFunc) ModifyResponse(res *http.Response) error
ModifyResponse modifies the response using the given function.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session provides information and storage about a connection.
func (*Session) Hijack ¶
Hijack takes control of the connection from the proxy. No further action will be taken by the proxy and the connection will be closed following the return of the hijacker.
func (*Session) HijackResponseWriter ¶
func (s *Session) HijackResponseWriter() (http.ResponseWriter, error)
HijackResponseWriter takes control of the response writer from the proxy.
func (*Session) IsSecure ¶
IsSecure returns whether the current session is from a secure connection, such as when receiving requests from a TLS connection that has been MITM'd.
func (*Session) MarkInsecure ¶
func (s *Session) MarkInsecure()
MarkInsecure marks the session as insecure.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package cybervillains provides the publically published Selenium project CyberVillains certificate and key.
|
Package cybervillains provides the publically published Selenium project CyberVillains certificate and key. |
Package fifo provides Group, which is a list of modifiers that are executed consecutively.
|
Package fifo provides Group, which is a list of modifiers that are executed consecutively. |
Package h2 contains basic HTTP/2 handling for Martian.
|
Package h2 contains basic HTTP/2 handling for Martian. |
grpc
Package grpc contains gRPC functionality for Martian proxy.
|
Package grpc contains gRPC functionality for Martian proxy. |
testing
Package testing contains a test fixture for working with gRPC over HTTP/2.
|
Package testing contains a test fixture for working with gRPC over HTTP/2. |
Package httpspec provides a modifier stack that has been preconfigured to provide spec-compliant HTTP proxy behavior.
|
Package httpspec provides a modifier stack that has been preconfigured to provide spec-compliant HTTP proxy behavior. |
Package log provides a universal logger for martian packages.
|
Package log provides a universal logger for martian packages. |
Package martiantest provides helper utilities for testing modifiers.
|
Package martiantest provides helper utilities for testing modifiers. |
Package messageview provides no-op snapshots for HTTP requests and responses.
|
Package messageview provides no-op snapshots for HTTP requests and responses. |
Package mitm provides tooling for MITMing TLS connections.
|
Package mitm provides tooling for MITMing TLS connections. |
Package proxyutil provides functionality for building proxies.
|
Package proxyutil provides functionality for building proxies. |