Documentation
¶
Index ¶
- func WithMITMCA(priv crypto.PrivateKey, cert *x509.Certificate) func(o *options)
- type Option
- func WithAddress(addr string) Option
- func WithHTTPClient(c *http.Client) Option
- func WithRequestLog(name string, logFn func(format string, a ...any)) Option
- func WithRewrite(old, new string) Option
- func WithRewriteFn(f func(u *url.URL)) Option
- func WithServerTLSConfig(tc *tls.Config) Option
- func WithVerboseLog() Option
- type Proxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithMITMCA ¶
func WithMITMCA(priv crypto.PrivateKey, cert *x509.Certificate) func(o *options)
WithMITMCA sets the CA used for MITM (men in the middle) when proxying HTTPS requests. It's used to generate TLS certificates matching the target host. Ideally the CA is the same as the one issuing the TLS certificate for the proxy set by WithServerTLSConfig.
Types ¶
type Option ¶
type Option func(o *options)
func WithAddress ¶
WithAddress will set the address the server will listen on. The format is as defined by net.Listen for a tcp connection.
func WithHTTPClient ¶
WithHTTPClient sets http.Client used to proxy requests to the target host.
func WithRequestLog ¶
WithRequestLog sets the proxy to log every request using logFn. It uses name as a prefix to the log.
func WithRewrite ¶
WithRewrite will replace old by new on the request URL host when forwarding it.
func WithRewriteFn ¶
WithRewriteFn calls f on the request *url.URL before forwarding it. It takes precedence over WithRewrite. Use if more control over the rewrite is needed.
func WithServerTLSConfig ¶
WithServerTLSConfig sets the TLS config for the server.
func WithVerboseLog ¶
func WithVerboseLog() Option
WithVerboseLog sets the proxy to log every request verbosely and enables debug level logging. WithRequestLog must be used as well, otherwise WithVerboseLog will not take effect.
type Proxy ¶
type Proxy struct {
*httptest.Server
// Port is the port Server is listening on.
Port string
// LocalhostURL is the server URL as "http(s)://localhost:PORT".
// Deprecated. Use Proxy.URL instead.
LocalhostURL string
// contains filtered or unexported fields
}
func New ¶
New returns a new Proxy ready for use. Use:
- WithAddress to set the proxy's address,
- WithRewrite or WithRewriteFn to rewrite the URL before forwarding the request.
Check the other With* functions for more options.
func (*Proxy) ProxiedRequests ¶
ProxiedRequests returns a slice with the "request log" with every request the proxy received.