Documentation
¶
Index ¶
- Constants
- func CopyRequestHeaders(dst, src http.Header)
- func CopyResponseHeaders(dst, src http.Header)
- func CreateUpstreamRequest(rw http.ResponseWriter, r *http.Request) *http.Request
- func SendBackResponse(w http.ResponseWriter, r *http.Request, res *http.Response, err error)
- type H2
- type H2C
- 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 ¶
func CopyRequestHeaders ¶
used in createUpstreamRequetst to copy the headers to the new req.
func CopyResponseHeaders ¶
Also used in httpproxy_capture, for forward http proxy
func CreateUpstreamRequest ¶
CreateUpstremRequest shallow-copies r into a new request that can be sent upstream.
Derived from reverseproxy.go in the standard Go httputil package.
Use with a roundtripper - HTTP1.1 or H2C or HTTPS, followed by SendBackResponse
func SendBackResponse ¶
Used by both ForwardHTTP and ForwardMesh, after RoundTrip is done. Will copy response headers and body
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 // 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 // Client side DialMeta func(context.Context, string, string) (io.ReadWriteCloser, error) TokenSource TokenSource // ResourceStore is used to resolve resources, is a registry of types and // objects. We're looking for handlers. ResourceStore ResourceStore `json:-` }
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.
curl localhost:9080/debug/vars --http2-prior-knowledge
func (*H2) DialContext ¶
func (*H2) WithResourceStore ¶
func (r *H2) WithResourceStore(rs ResourceStore)
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.Client, 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.