action

package
v0.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package action implements request handlers (proxy, static, serve, pass, drop).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnStatsContext

func NewConnStatsContext(ctx context.Context, cs *ConnStats) context.Context

NewConnStatsContext returns a context carrying the given ConnStats.

Types

type ConnStats

type ConnStats struct {
	BytesRx int64 // atomic: client → upstream
	BytesTx int64 // atomic: upstream → client
}

ConnStats accumulates byte counts from hijacked connection relays. Used only for WebSocket and CONNECT paths where ResponseCapture is bypassed after hijack.

func ConnStatsFromContext

func ConnStatsFromContext(ctx context.Context) *ConnStats

ConnStatsFromContext extracts ConnStats from the context, or nil.

func (*ConnStats) AddRx

func (cs *ConnStats) AddRx(n int64)

AddRx atomically adds to the received byte counter.

func (*ConnStats) AddTx

func (cs *ConnStats) AddTx(n int64)

AddTx atomically adds to the transmitted byte counter.

func (*ConnStats) LoadRx

func (cs *ConnStats) LoadRx() int64

LoadRx atomically loads the received byte counter.

func (*ConnStats) LoadTx

func (cs *ConnStats) LoadTx() int64

LoadTx atomically loads the transmitted byte counter.

type CountingReader

type CountingReader struct {
	N int64
	// contains filtered or unexported fields
}

CountingReader wraps an io.ReadCloser and counts bytes read. Not safe for concurrent use — r.Body is read by a single goroutine.

func (*CountingReader) Close

func (cr *CountingReader) Close() error

Close implements io.Closer.

func (*CountingReader) Read

func (cr *CountingReader) Read(p []byte) (int, error)

Read implements io.Reader with byte counting.

func (*CountingReader) Reset

func (cr *CountingReader) Reset(rc io.ReadCloser)

Reset reinitializes the CountingReader for reuse from a pool.

type Drop

type Drop struct{}

Drop aborts the connection without sending any HTTP response. Uses http.ErrAbortHandler which is handled by Go's HTTP server:

  • HTTP/1.1: connection is closed with no response written
  • HTTP/2: stream is reset (RST_STREAM)

func (*Drop) ServeHTTP

func (d *Drop) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy forwards requests to an upstream server. WebSocket upgrades are detected and handled via bidirectional TCP relay.

When the upstream contains template placeholders (e.g. {target}), they are resolved per-request from the route's balancer and set variables.

func NewProxy

func NewProxy(act *config.Action, svcCfg *config.ServerConfig) (*Proxy, error)

NewProxy creates a reverse proxy handler for the given action config. svcCfg provides optional service-level transport tuning.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Proxy) SetFallback

func (p *Proxy) SetFallback(h http.Handler)

SetFallback sets the handler invoked when the primary action fails.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maps action names to their http.Handler implementations.

func Build

func Build(actions map[string]*config.Action, resolver *resource.Resolver, hints *RouteHints, svcCfg *config.ServerConfig) (*Registry, error)

Build constructs all action handlers from config. svcCfg is optional service-level configuration for transport tuning.

func (*Registry) Get

func (reg *Registry) Get(name string) http.Handler

Get returns the handler for a named action.

func (*Registry) GetFallback

func (reg *Registry) GetFallback(name string) http.Handler

GetFallback returns the fallback handler for a named action, or nil if none is configured.

type RouteHints

type RouteHints struct {
	PathByAction map[string]string
}

RouteHints maps action names to route paths for prefix stripping.

type Serve

type Serve struct {
	// contains filtered or unexported fields
}

Serve is an action that serves files from a directory or a single file.

func NewServe

func NewServe(act *config.Action, routePath string) (*Serve, error)

NewServe creates a file-serving handler.

func (*Serve) ServeHTTP

func (s *Serve) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Static

type Static struct {
	// contains filtered or unexported fields
}

Static returns a fixed response with pre-computed body, headers, and status. If the body contains template variables like {domain}, {match.domain}, {path}, {match.path}, {method}, they are interpolated at request time.

func NewStatic

func NewStatic(act *config.Action, resolver *resource.Resolver) (*Static, error)

NewStatic creates a static response handler.

func (*Static) ServeHTTP

func (s *Static) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL