Documentation ¶
Overview ¶
Package martian provides an HTTP/1.1 proxy with an API for configurable request and response modifiers.
Index ¶
- Variables
- type Context
- func (ctx *Context) APIRequest()
- func (ctx *Context) Get(key string) (interface{}, bool)
- func (c *Context) GetSessionBoolValue(i string) bool
- func (c *Context) GetSessionIntValue(i string) int
- func (c *Context) GetSessionStringValue(i string) string
- func (ctx *Context) ID() string
- func (ctx *Context) IsAPIRequest() bool
- func (ctx *Context) Session() *Session
- func (ctx *Context) Set(key string, val interface{})
- func (ctx *Context) SkipLogging()
- func (ctx *Context) SkipRoundTrip()
- func (ctx *Context) SkippingLogging() bool
- func (ctx *Context) SkippingRoundTrip() bool
- type MultiError
- type Proxy
- func (p *Proxy) Close()
- func (p *Proxy) Closing() bool
- func (p *Proxy) GetMaxContentLength() int
- func (p *Proxy) Serve(l net.Listener, ctx context.Context) error
- func (p *Proxy) SetAuth(user, pass string)
- func (p *Proxy) SetGMOnly(enable bool)
- func (p *Proxy) SetGMPrefer(enable bool)
- func (p *Proxy) SetGMTLS(enable bool)
- func (p *Proxy) SetH2(enable bool)
- func (p *Proxy) SetHTTPForceClose(enable bool)
- func (p *Proxy) SetLowhttpConfig(config []lowhttp.LowhttpOpt)
- func (p *Proxy) SetMITM(config *mitm.Config)
- func (p *Proxy) SetMaxContentLength(i int)
- func (p *Proxy) SetRequestModifier(reqmod RequestModifier)
- func (p *Proxy) SetResponseModifier(resmod ResponseModifier)
- func (p *Proxy) SetTimeout(timeout time.Duration)
- type RequestModifier
- type RequestModifierFunc
- type RequestResponseModifier
- type ResponseModifier
- type ResponseModifierFunc
- type S5Config
- func (c *S5Config) ConnectionFallback(src, proxiedConn net.Conn) error
- func (c *S5Config) HandleS5Request(conn net.Conn) (net.Conn, error)
- func (c *S5Config) Handshake(conn net.Conn) (net.Conn, error)
- func (c *S5Config) HijackSource(src, proxiedConn net.Conn) (net.Conn, net.Conn, bool, error)
- func (c *S5Config) IsSocks5HandleShake(conn net.Conn) (fConn net.Conn, _ bool, _ byte, _ error)
- func (c *S5Config) ServeConn(conn net.Conn) error
- type Session
- func (s *Session) Get(key string) (interface{}, bool)
- func (s *Session) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (s *Session) Hijacked() bool
- func (s *Session) ID() string
- func (s *Session) IsSecure() bool
- func (s *Session) MarkInsecure()
- func (s *Session) MarkSecure()
- func (s *Session) Set(key string, val interface{})
Constants ¶
This section is empty.
Variables ¶
var IsDroppedError = utils.Error("dropped")
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 NewContext ¶
NewContext returns a context for the in-flight HTTP request.
func TestContext ¶
func TestContext(req *http.Request, conn net.Conn, bw *bufio.ReadWriter, p *Proxy) (ctx *Context, remove func(), err error)
TestContext builds a new session and associated context and returns the context and a function to remove the associated context. If it fails to generate either a new session or a new context it will return an error. Intended for tests only.
func (*Context) APIRequest ¶
func (ctx *Context) APIRequest()
APIRequest marks the requests as a request to the proxy API.
func (*Context) GetSessionBoolValue ¶
func (*Context) GetSessionIntValue ¶
func (*Context) GetSessionStringValue ¶
func (*Context) IsAPIRequest ¶
IsAPIRequest returns true when the request patterns matches a pattern in the proxy mux. The mux is usually defined as a parameter to the api.Forwarder, which uses http.DefaultServeMux by default.
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) SkipLogging ¶
func (ctx *Context) SkipLogging()
SkipLogging skips logging by Martian loggers for the current request.
func (*Context) SkipRoundTrip ¶
func (ctx *Context) SkipRoundTrip()
SkipRoundTrip skips the round trip for the current request.
func (*Context) SkippingLogging ¶
SkippingLogging returns whether the current request / response pair will be logged.
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 {
// 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) GetMaxContentLength ¶
func (*Proxy) SetGMPrefer ¶
SetGMPrefer sets the switch to prefer using GM style TLS
func (*Proxy) SetHTTPForceClose ¶ added in v1.3.3
SetHTTPForceClose sets proxy no-keepalive
func (*Proxy) SetLowhttpConfig ¶
func (p *Proxy) SetLowhttpConfig(config []lowhttp.LowhttpOpt)
SetLowhttpConfig sets the lowhttp config
func (*Proxy) SetMaxContentLength ¶
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) SetTimeout ¶
SetTimeout sets the request timeout of the 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 S5Config ¶
type S5Config struct { HandshakeTimeout time.Duration Debug bool DownstreamHTTPProxy string ProxyUsername string ProxyPassword string }
func NewSocks5Config ¶
func NewSocks5Config() *S5Config
func (*S5Config) ConnectionFallback ¶
func (*S5Config) HandleS5Request ¶
func (*S5Config) HijackSource ¶
func (*S5Config) IsSocks5HandleShake ¶
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) 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 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. |
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. |