Documentation
¶
Overview ¶
Package proxygateway implements VORTEX's protocol gateway (build plan M2.6): it inspects each request and dispatches WebSocket upgrades, gRPC calls, and plain HTTP to the appropriate handler. WebSocket connections are tunnelled with M2.1's tcp.Tunnel; gRPC is proxied transparently over HTTP/2. Standard library only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGRPC ¶
IsGRPC reports whether req is a gRPC call, identified by a Content-Type of application/grpc (covering grpc, grpc+proto, grpc+json, grpc-web).
func IsWebSocketUpgrade ¶
IsWebSocketUpgrade reports whether req is a WebSocket upgrade handshake: an "Upgrade: websocket" header and a Connection header listing "Upgrade" (both case-insensitive, per RFC 6455).
func ProxyWebSocket ¶
func ProxyWebSocket(w http.ResponseWriter, req *http.Request, backendURL string, pool *tcp.Pool) error
ProxyWebSocket proxies a WebSocket connection: it dials the backend, replays the upgrade handshake, relays the backend's 101 response to the client, then tunnels bytes bidirectionally with tcp.Tunnel. The client connection is hijacked, so w must implement http.Hijacker. backendURL is the upstream base URL (scheme is ignored; host:port is used).
Types ¶
type GRPCProxy ¶
type GRPCProxy struct {
// contains filtered or unexported fields
}
GRPCProxy transparently reverse-proxies gRPC (HTTP/2) requests, preserving HTTP/2 trailers (gRPC carries its status in trailers).
func NewGRPCProxy ¶
func NewGRPCProxy(cfg GRPCProxyConfig) (*GRPCProxy, error)
NewGRPCProxy validates cfg and builds a GRPCProxy. If no Balancer is supplied, a round-robin balancer over Backends is created.
type GRPCProxyConfig ¶
type GRPCProxyConfig struct {
Backends []proxyhttp.BackendAddr
Balancer proxyhttp.Balancer
Timeout time.Duration // 0 = no timeout
}
GRPCProxyConfig configures a GRPCProxy.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway dispatches each request to the WebSocket proxy, gRPC proxy, or plain HTTP handler, in that priority order.
func NewGateway ¶
func NewGateway(cfg GatewayConfig) (*Gateway, error)
NewGateway validates cfg and constructs a Gateway.
func (*Gateway) ServeHTTP ¶
func (g *Gateway) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP dispatches by protocol: WebSocket upgrade → gRPC → plain HTTP.
func (*Gateway) Stats ¶
func (g *Gateway) Stats() GatewayStats
Stats returns a snapshot of per-protocol request counts.
type GatewayConfig ¶
type GatewayConfig struct {
// HTTPHandler handles plain HTTP requests (the M2.2 proxy handler). Required.
HTTPHandler http.Handler
// GRPCProxy handles application/grpc requests. Optional: when nil, gRPC
// requests fall through to HTTPHandler.
GRPCProxy *GRPCProxy
// TCPPool backs WebSocket tunneling. Optional (a direct dial is used if nil).
TCPPool *tcp.Pool
// Sticky pins a client IP to a backend across WebSocket reconnects. Optional.
Sticky *StickySession
// WSBackends are the upstreams for WebSocket routing. When empty, WebSocket
// upgrades fall through to HTTPHandler (which returns its WS stub).
WSBackends []proxyhttp.BackendAddr
}
GatewayConfig configures a Gateway.
type GatewayStats ¶
GatewayStats counts requests dispatched by protocol.
type StickySession ¶
type StickySession struct {
// contains filtered or unexported fields
}
StickySession maps a client IP to the backend it was first routed to, so a WebSocket client reconnects to the same backend. Safe for concurrent use.
func NewStickySession ¶
func NewStickySession() *StickySession
NewStickySession returns an empty sticky-session table.
func (*StickySession) Delete ¶
func (s *StickySession) Delete(clientIP string)
Delete removes the sticky entry for clientIP.
func (*StickySession) Get ¶
func (s *StickySession) Get(clientIP string) (string, bool)
Get returns the sticky backend for clientIP, and whether one is set.
func (*StickySession) Set ¶
func (s *StickySession) Set(clientIP, backendAddr string)
Set records the backend for clientIP.