Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conn ¶
type Conn struct { // HostName is the hostname field that was sent to the request router. // In the case of TLS, this is the SNI header, in the case of HTTPHost // route, it will be the host header. In the case of a fixed // route, i.e. those created with AddRoute(), this will always be // empty. This can be useful in the case where further routing decisions // need to be made in the Target impementation. HostName string // Peeked are the bytes that have been read from Conn for the // purposes of route matching, but have not yet been consumed // by Read calls. It set to nil by Read when fully consumed. Peeked []byte // Conn is the underlying connection. // It can be type asserted against *net.TCPConn or other types // as needed. It should not be read from directly unless // Peeked is nil. net.Conn }
Conn is an incoming connection that has had some bytes read from it to determine how to route the connection. The Read method stitches the peeked bytes and unread bytes back together.
type DialProxy ¶
type DialProxy struct { // Addr is the TCP address to proxy to. Addr string // KeepAlivePeriod sets the period between TCP keep alives. // If zero, a default is used. To disable, use a negative number. // The keep-alive is used for both the client connection and KeepAlivePeriod time.Duration // DialTimeout optionally specifies a dial timeout. // If zero, a default is used. // If negative, the timeout is disabled. DialTimeout time.Duration // DialContext optionally specifies an alternate dial function // for TCP targets. If nil, the standard // net.Dialer.DialContext method is used. DialContext func(ctx context.Context, network, address string) (net.Conn, error) // OnDialError optionally specifies an alternate way to handle errors dialing Addr. // If nil, the error is logged and src is closed. // If non-nil, src is not closed automatically. OnDialError func(src net.Conn, dstDialErr error) // ProxyProtocolVersion optionally specifies the version of // HAProxy's PROXY protocol to use. The PROXY protocol provides // connection metadata to the DialProxy target, via a header // inserted ahead of the client's traffic. The DialProxy target // must explicitly support and expect the PROXY header; there is // no graceful downgrade. // If zero, no PROXY header is sent. Currently, version 1 is supported. ProxyProtocolVersion int }
DialProxy implements Target by dialing a new connection to Addr and then proxying data back and forth.
The To func is a shorthand way of creating a DialProxy.
func (*DialProxy) HandleConn ¶
HandleConn implements the Target interface.
type Proxy ¶
type Proxy struct { // ListenFunc optionally specifies an alternate listen // function. If nil, net.Dial is used. // The provided net is always "tcp". ListenFunc func(net, laddr string) (net.Listener, error) // contains filtered or unexported fields }
Proxy is a proxy. Its zero value is a valid proxy that does nothing. Call methods to add routes before calling Start or Run.
The order that routes are added in matters; each is matched in the order registered.
func (*Proxy) AddRoute ¶
AddRoute appends an always-matching route to the ipPort listener, directing any connection to dest.
This is generally used as either the only rule (for simple TCP proxies), or as the final fallback rule for an ipPort.
The ipPort is any valid net.Listen TCP address.
func (*Proxy) Run ¶
Run is calls Start, and then Wait.
It blocks until there's an error. The return value is always non-nil.
type Target ¶
type Target interface { // HandleConn is called when an incoming connection is // matched. After the call to HandleConn, the tcpproxy // package never touches the conn again. Implementations are // responsible for closing the connection when needed. // // The concrete type of conn will be of type *Conn if any // bytes have been consumed for the purposes of route // matching. HandleConn(net.Conn) }
Target is what an incoming matched connection is sent to.