Documentation
¶
Overview ¶
Package forwarder provides a simple forward proxy server. The proxy can be protected with HTTP basic authentication. It can also forward connections to a parent proxy, and authorize connections against that. Both local, and parent credentials can be set via environment variables.
Index ¶
- Constants
- Variables
- func LoadCertificateFromTLSConfig(dst *tls.Config, src *TLSConfig) error
- func NewHTTPTransport(cfg *HTTPTransportConfig, r *net.Resolver) *http.Transport
- func NewResolver(cfg *DNSConfig, log log.Logger) (*net.Resolver, error)
- func OpenFileParser(flag int, perm, dirPerm os.FileMode) func(val string) (*os.File, error)
- func ParseDNSAddress(val string) (netip.AddrPort, error)
- func ParseProxyURL(val string) (*url.URL, error)
- func ParseUserInfo(val string) (*url.Userinfo, error)
- func ReadURL(u *url.URL, rt http.RoundTripper) (string, error)
- func RedactHostPortUser(hpu *HostPortUser) string
- type APIHandler
- type CredentialsMatcher
- type DNSConfig
- type HTTPProxy
- type HTTPProxyConfig
- type HTTPServer
- type HTTPServerConfig
- type HTTPTransportConfig
- type HostPortUser
- type LoggingPACResolver
- type PACResolver
- type ProxyFunc
- type ProxyLocalhostMode
- type Scheme
- type TLSConfig
Constants ¶
const ErrorHeader = "X-Forwarder-Error"
ErrorHeader is the header that is set on error responses with the error message.
Variables ¶
var ErrProxyLocalhost = denyError{errors.New("localhost proxying is disabled")}
Functions ¶
func LoadCertificateFromTLSConfig ¶ added in v1.0.1
func NewHTTPTransport ¶
func NewHTTPTransport(cfg *HTTPTransportConfig, r *net.Resolver) *http.Transport
func OpenFileParser ¶
OpenFileParser returns a parser that calls os.OpenFile. If dirPerm is set it will create the directory if it does not exist. For empty path the parser returns nil file and nil error.
func ParseUserInfo ¶
ParseUserInfo parses a user:password string into *url.Userinfo. Username and password cannot be empty.
func RedactHostPortUser ¶
func RedactHostPortUser(hpu *HostPortUser) string
Types ¶
type APIHandler ¶
type APIHandler struct {
// contains filtered or unexported fields
}
APIHandler serves API endpoints. It provides health and readiness endpoints prometheus metrics, and pprof debug endpoints.
func NewAPIHandler ¶
func NewAPIHandler(r prometheus.Gatherer, ready func() bool, config, pac string) *APIHandler
func (*APIHandler) ServeHTTP ¶
func (h *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type CredentialsMatcher ¶
type CredentialsMatcher struct {
// contains filtered or unexported fields
}
func NewCredentialsMatcher ¶
func NewCredentialsMatcher(credentials []*HostPortUser, log log.Logger) (*CredentialsMatcher, error)
type DNSConfig ¶
type DNSConfig struct { // Servers is a list of DNS servers to use. // If provided with multiple servers, the first one is used as primary server, the rest are used as a fallback. Servers []netip.AddrPort // Timeout is the timeout for DNS queries. Timeout time.Duration }
func DefaultDNSConfig ¶
func DefaultDNSConfig() *DNSConfig
type HTTPProxy ¶
type HTTPProxy struct { TLSConfig *tls.Config Listener net.Listener // contains filtered or unexported fields }
func NewHTTPProxy ¶
func NewHTTPProxy(cfg *HTTPProxyConfig, pr PACResolver, cm *CredentialsMatcher, rt http.RoundTripper, log log.Logger) (*HTTPProxy, error)
func (*HTTPProxy) Addr ¶
Addr returns the address the server is listening on or an empty string if the server is not running.
type HTTPProxyConfig ¶
type HTTPProxyConfig struct { HTTPServerConfig ProxyLocalhost ProxyLocalhostMode UpstreamProxy *url.URL UpstreamProxyFunc ProxyFunc RequestModifiers []martian.RequestModifier ResponseModifiers []martian.ResponseModifier ConnectPassthrough bool CloseAfterReply bool // TestingHTTPHandler uses Martian's [http.Handler] implementation // over [http.Server] instead of the default TCP server. TestingHTTPHandler bool }
func DefaultHTTPProxyConfig ¶
func DefaultHTTPProxyConfig() *HTTPProxyConfig
func (*HTTPProxyConfig) Validate ¶
func (c *HTTPProxyConfig) Validate() error
type HTTPServer ¶
func NewHTTPServer ¶
func NewHTTPServer(cfg *HTTPServerConfig, h http.Handler, log log.Logger) (*HTTPServer, error)
func (*HTTPServer) Addr ¶
func (hs *HTTPServer) Addr() string
Addr returns the address the server is listening on or an empty string if the server is not running.
func (*HTTPServer) Ready ¶
func (hs *HTTPServer) Ready() bool
Ready returns true if the server is running and ready to accept requests.
type HTTPServerConfig ¶
type HTTPServerConfig struct { Protocol Scheme Addr string TLSConfig ReadTimeout time.Duration ReadHeaderTimeout time.Duration WriteTimeout time.Duration LogHTTPMode httplog.Mode PromNamespace string PromRegistry prometheus.Registerer BasicAuth *url.Userinfo }
func DefaultHTTPServerConfig ¶
func DefaultHTTPServerConfig() *HTTPServerConfig
func (*HTTPServerConfig) Validate ¶
func (c *HTTPServerConfig) Validate() error
type HTTPTransportConfig ¶
type HTTPTransportConfig struct { // DialTimeout is the maximum amount of time a dial will wait for // a connect to complete. // // With or without a timeout, the operating system may impose // its own earlier timeout. For instance, TCP timeouts are // often around 3 minutes. DialTimeout time.Duration // KeepAlive specifies the interval between keep-alive // probes for an active network connection. // If zero, keep-alive probes are sent with a default value // (currently 15 seconds), if supported by the protocol and operating // system. Network protocols or operating systems that do // not support keep-alives ignore this field. // If negative, keep-alive probes are disabled. KeepAlive time.Duration // TLSHandshakeTimeout specifies the maximum amount of time waiting to // wait for a TLS handshake. Zero means no timeout. TLSHandshakeTimeout time.Duration // MaxIdleConns controls the maximum number of idle (keep-alive) // connections across all hosts. Zero means no limit. MaxIdleConns int // MaxIdleConnsPerHost, if non-zero, controls the maximum idle // (keep-alive) connections to keep per-host. If zero, // DefaultMaxIdleConnsPerHost is used. MaxIdleConnsPerHost int // MaxConnsPerHost optionally limits the total number of // connections per host, including connections in the dialing, // active, and idle states. On limit violation, dials will block. // // Zero means no limit. MaxConnsPerHost int // IdleConnTimeout is the maximum amount of time an idle // (keep-alive) connection will remain idle before closing // itself. // Zero means no limit. IdleConnTimeout time.Duration // ResponseHeaderTimeout, if non-zero, specifies the amount of // time to wait for a server's response headers after fully // writing the request (including its body, if any). This // time does not include the time to read the response body. ResponseHeaderTimeout time.Duration // ExpectContinueTimeout, if non-zero, specifies the amount of // time to wait for a server's first response headers after fully // writing the request headers if the request has an // "Expect: 100-continue" header. Zero means no timeout and // causes the body to be sent immediately, without // waiting for the server to approve. // This time does not include the time to send the request header. ExpectContinueTimeout time.Duration TLSConfig }
func DefaultHTTPTransportConfig ¶
func DefaultHTTPTransportConfig() *HTTPTransportConfig
type HostPortUser ¶
func ParseHostPortUser ¶
func ParseHostPortUser(val string) (*HostPortUser, error)
ParseHostPortUser parses a user:password@host:port string into HostUser. User and password cannot be empty.
func (*HostPortUser) Validate ¶
func (hpu *HostPortUser) Validate() error
type LoggingPACResolver ¶
type LoggingPACResolver struct { Resolver PACResolver Logger log.Logger }
func (*LoggingPACResolver) FindProxyForURL ¶
type PACResolver ¶
type ProxyLocalhostMode ¶
type ProxyLocalhostMode string
const ( DenyProxyLocalhost ProxyLocalhostMode = "deny" AllowProxyLocalhost ProxyLocalhostMode = "allow" DirectProxyLocalhost ProxyLocalhostMode = "direct" )
func (ProxyLocalhostMode) String ¶
func (m ProxyLocalhostMode) String() string
func (*ProxyLocalhostMode) UnmarshalText ¶
func (m *ProxyLocalhostMode) UnmarshalText(text []byte) error
type TLSConfig ¶
type TLSConfig struct { // InsecureSkipVerify controls whether a client verifies the server's // certificate chain and host name. If InsecureSkipVerify is true, crypto/tls // accepts any certificate presented by the server and any host name in that // certificate. In this mode, TLS is susceptible to machine-in-the-middle // attacks unless custom verification is used. This should be used only for // testing or in combination with VerifyConnection or VerifyPeerCertificate. InsecureSkipVerify bool // CertFile is the path to the TLS certificate. CertFile string // KeyFile is the path to the TLS private key of the certificate. KeyFile string }
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
Package pac provides a PAC file parser and evaluator.
|
Package pac provides a PAC file parser and evaluator. |
utils
|
|