Documentation
¶
Index ¶
- Constants
- type H2
- func (st *H2) DialContext(ctx context.Context, net, addr string) (net.Conn, error)
- func (st *H2) HandleTunReq(writer http.ResponseWriter, request *http.Request)
- func (st *H2) InitMux(mux *http.ServeMux)
- func (r *H2) Provision(ctx context.Context) error
- func (st *H2) ProxyHTTP(writer http.ResponseWriter, request *http.Request)
- func (st *H2) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (r *H2) Start() error
- func (r *H2) WithResourceStore(rs ResourceStore)
- type H2C
- type Proxy1
- type ResourceStore
- type Stats
- type StreamHttpClient
- func (s *StreamHttpClient) Close() error
- func (s *StreamHttpClient) CloseWrite() error
- func (s *StreamHttpClient) Header() http.Header
- func (s *StreamHttpClient) LocalAddr() net.Addr
- func (s *StreamHttpClient) Read(b []byte) (n int, err error)
- func (s *StreamHttpClient) RemoteAddr() net.Addr
- func (s *StreamHttpClient) RequestHeader() http.Header
- func (s *StreamHttpClient) SetDeadline(t time.Time) error
- func (s *StreamHttpClient) SetReadDeadline(t time.Time) error
- func (s *StreamHttpClient) SetWriteDeadline(t time.Time) error
- func (s *StreamHttpClient) State() *StreamState
- func (s *StreamHttpClient) Write(b []byte) (n int, err error)
- type StreamHttpServer
- func (s *StreamHttpServer) Close() error
- func (s *StreamHttpServer) CloseWrite() error
- func (s *StreamHttpServer) Context() context.Context
- func (s *StreamHttpServer) Header() http.Header
- func (s *StreamHttpServer) LocalAddr() net.Addr
- func (s *StreamHttpServer) Read(b []byte) (n int, err error)
- func (s *StreamHttpServer) RemoteAddr() net.Addr
- func (s *StreamHttpServer) RequestHeader() http.Header
- func (s *StreamHttpServer) SetDeadline(t time.Time) error
- func (s *StreamHttpServer) SetReadDeadline(t time.Time) error
- func (s *StreamHttpServer) SetWriteDeadline(t time.Time) error
- func (s *StreamHttpServer) State() *StreamState
- func (s *StreamHttpServer) TLSConnectionState() *tls.ConnectionState
- func (s *StreamHttpServer) Write(b []byte) (n int, err error)
- type StreamState
- type TokenSource
Constants ¶
const ConnectOverrideHeader = "x-host"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type H2 ¶
type H2 struct {
//MaxHandlers: 0,
//MaxConcurrentStreams: 0,
//MaxDecoderHeaderTableSize: 0,
//MaxEncoderHeaderTableSize: 0,
//MaxReadFrameSize: 0,
//PermitProhibitedCipherSuites: false,
//IdleTimeout: 0,
//MaxUploadBufferPerConnection: 0,
//MaxUploadBufferPerStream: 0,
//NewWriteScheduler: nil,
//CountError: nil,
// Addr - included
http.Server
NetListener net.Listener `json:"-"`
// The key is a route as defined by go ServerMux.
// The value can be:
// - a URL - in which case it's a reverse proxy
// - a string that is a resource name - in which case it's a Handler
// Other values like TCP proxy can be defined later.
Routes map[string]string
// The actual mux that is configured. Will be mapped to a H2C/H1 server by
// default, assuming ambient or secure network.
Mux *http.ServeMux `json:"-"`
SSHStreamHandler func(net.Conn) error `json:"-"`
// DialMeta opens a TCP connection to a client using -R on 80
// or 443, using the FQDN. This and next 2 functions integrate
// with the 'mesh' layer, discovering or using connections.
DialMeta func(context.Context, string, string) (io.ReadWriteCloser, error) `json:"-"`
FindRoundTripper func(ctx context.Context, urlOrHost string) (http.RoundTripper, error)
// RegisterReverse handles a mapping of '-R' remote accept connections.
// HTTP, SSH are treated specially.
RegisterReverse func(ctx context.Context, host string, rt http.RoundTripper)
TokenSource TokenSource `json:"-"`
// ResourceStore is used to resolve resources, is a registry of types and
// objects. We're looking for handlers.
ResourceStore ResourceStore `json:"-"`
Logger *slog.Logger
// contains filtered or unexported fields
}
H2 is the HTTP/2 transport. It handles incoming http requests as mux and may be used as a http server as well.
As a transport it can accept and dial connections, with proxy support.
Test with: curl localhost:9080/debug/vars --http2-prior-knowledge
func (*H2) DialContext ¶
func (*H2) HandleTunReq ¶
func (st *H2) HandleTunReq(writer http.ResponseWriter, request *http.Request)
HandleTun handles a request for '-L' style tunneling - the remote is asking to proxy a TCP connection.
In-process services (SSH and HTTP) are handled directly ¶
Local ports and remote destinations can be forwarded only with authz, for 'owner' and allowed users.
func (*H2) WithResourceStore ¶
func (r *H2) WithResourceStore(rs ResourceStore)
type H2C ¶
H2C is a per-client http transport.
Can't do h2c using the std client - need custom code.
type ResourceStore ¶
type Stats ¶
type Stats struct {
Open time.Time
// last receive from local (and send to remote)
LastWrite time.Time
// last receive from remote (and send to local)
LastRead time.Time
// Sent from client to server ( client is initiator of the proxy )
SentBytes int
SentPackets int
// Received from server to client
RcvdBytes int
RcvdPackets int
}
Stats holds telemetry for a stream or peer.
type StreamHttpClient ¶
type StreamHttpClient struct {
StreamState
Request *http.Request
Response *http.Response
RequestInPipe io.WriteCloser
}
func NewStreamH2 ¶
func NewStreamH2(ctx context.Context, hc http.RoundTripper, addr string, tcpaddr string, mds TokenSource) (*StreamHttpClient, error)
NewStreamH2 creates a H2 stream using POST.
Will use the token provider if not nil.
func (*StreamHttpClient) Close ¶
func (s *StreamHttpClient) Close() error
func (*StreamHttpClient) CloseWrite ¶
func (s *StreamHttpClient) CloseWrite() error
func (*StreamHttpClient) Header ¶
func (s *StreamHttpClient) Header() http.Header
func (*StreamHttpClient) LocalAddr ¶
func (s *StreamHttpClient) LocalAddr() net.Addr
func (*StreamHttpClient) RemoteAddr ¶
func (s *StreamHttpClient) RemoteAddr() net.Addr
func (*StreamHttpClient) RequestHeader ¶
func (s *StreamHttpClient) RequestHeader() http.Header
func (*StreamHttpClient) SetDeadline ¶
func (s *StreamHttpClient) SetDeadline(t time.Time) error
func (*StreamHttpClient) SetReadDeadline ¶
func (s *StreamHttpClient) SetReadDeadline(t time.Time) error
func (*StreamHttpClient) SetWriteDeadline ¶
func (s *StreamHttpClient) SetWriteDeadline(t time.Time) error
func (*StreamHttpClient) State ¶
func (s *StreamHttpClient) State() *StreamState
type StreamHttpServer ¶
type StreamHttpServer struct {
StreamState
Request *http.Request
TLS *tls.ConnectionState
ResponseWriter http.ResponseWriter
// If set, the function will be called when Close() is called.
ReadCloser func()
}
StreamHttpServer implements net.Conn on top of a H2 stream.
func NewStreamServerRequest ¶
func NewStreamServerRequest(r *http.Request, w http.ResponseWriter) *StreamHttpServer
Create a new stream from a HTTP request/response.
For accepted requests, http2/server.go newWriterAndRequests populates the request based on the headers. Server validates method, path and scheme=http|https. Req.Body is a pipe - similar with what we use for egress. Request context is based on stream context, which is a 'with cancel' based on the serverConn baseCtx.
func (*StreamHttpServer) Close ¶
func (s *StreamHttpServer) Close() error
func (*StreamHttpServer) CloseWrite ¶
func (s *StreamHttpServer) CloseWrite() error
func (*StreamHttpServer) Context ¶
func (s *StreamHttpServer) Context() context.Context
func (*StreamHttpServer) Header ¶
func (s *StreamHttpServer) Header() http.Header
func (*StreamHttpServer) LocalAddr ¶
func (s *StreamHttpServer) LocalAddr() net.Addr
func (*StreamHttpServer) RemoteAddr ¶
func (s *StreamHttpServer) RemoteAddr() net.Addr
func (*StreamHttpServer) RequestHeader ¶
func (s *StreamHttpServer) RequestHeader() http.Header
func (*StreamHttpServer) SetDeadline ¶
func (s *StreamHttpServer) SetDeadline(t time.Time) error
func (*StreamHttpServer) SetReadDeadline ¶
func (s *StreamHttpServer) SetReadDeadline(t time.Time) error
func (*StreamHttpServer) SetWriteDeadline ¶
func (s *StreamHttpServer) SetWriteDeadline(t time.Time) error
func (*StreamHttpServer) State ¶
func (s *StreamHttpServer) State() *StreamState
func (*StreamHttpServer) TLSConnectionState ¶
func (s *StreamHttpServer) TLSConnectionState() *tls.ConnectionState
TLSConnectionState implements the tls.Conn interface. By default uses the request TLS state, but can be replaced with a synthetic one (for example with ztunnel or other split TLS).
type StreamState ¶
type StreamState struct {
// It is the key in the Active table.
// Streams may also have local ids associated with the transport.
StreamId string
// WritErr indicates that Write failed - timeout or a RST closing the stream.
WriteErr error `json:"-"`
// ReadErr, if not nil, indicates that Read() failed - connection was closed with RST
// or timedout instead of FIN
ReadErr error `json:"-"`
Stats
// Original or infered destination.
Dest string
}
StreamState provides metadata about a stream.
It includes errors, stats, other metadata. The Stream interface wraps a net.Conn with context and state.