internal

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1024
	MB = 1024 * KB

	ENV_PREFIX = "THRUSTER_"
)

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(options HandlerOptions) http.Handler

func NewProxyHandler

func NewProxyHandler(targetUrl *url.URL, badGatewayPage string) http.Handler

func NewStashingWriter

func NewStashingWriter(limit int, dest io.Writer) *stashingWriter

func ProxyErrorHandler

func ProxyErrorHandler(badGatewayPage string) func(w http.ResponseWriter, r *http.Request, err error)

Types

type Cache

type Cache interface {
	Get(key CacheKey) ([]byte, bool)
	Set(key CacheKey, value []byte, expiresAt time.Time)
}

type CacheHandler

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

func NewCacheHandler

func NewCacheHandler(cache Cache, maxBodySize int, next http.Handler) *CacheHandler

func (*CacheHandler) ServeHTTP

func (h *CacheHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type CacheKey added in v0.0.2

type CacheKey uint64

type CacheableResponse

type CacheableResponse struct {
	StatusCode    int
	HttpHeader    http.Header
	Body          []byte
	VariantHeader http.Header
	// contains filtered or unexported fields
}

func CacheableResponseFromBuffer

func CacheableResponseFromBuffer(b []byte) (CacheableResponse, error)

func NewCacheableResponse

func NewCacheableResponse(w http.ResponseWriter, maxBodyLength int) *CacheableResponse

func (*CacheableResponse) CacheStatus

func (c *CacheableResponse) CacheStatus() (bool, time.Time)

func (*CacheableResponse) Header

func (c *CacheableResponse) Header() http.Header

func (*CacheableResponse) ToBuffer

func (c *CacheableResponse) ToBuffer() ([]byte, error)

func (*CacheableResponse) Write

func (c *CacheableResponse) Write(bytes []byte) (int, error)

func (*CacheableResponse) WriteCachedResponse

func (c *CacheableResponse) WriteCachedResponse(w http.ResponseWriter)

func (*CacheableResponse) WriteHeader

func (c *CacheableResponse) WriteHeader(statusCode int)

type Config

type Config struct {
	TargetPort      int
	UpstreamCommand string
	UpstreamArgs    []string

	CacheSizeBytes        int
	MaxCacheItemSizeBytes int
	XSendfileEnabled      bool
	MaxRequestBody        int

	SSLDomain        string
	ACMEDirectoryURL string
	EAB_KID          string
	EAB_HMACKey      string
	StoragePath      string
	BadGatewayPage   string

	HttpPort         int
	HttpsPort        int
	HttpIdleTimeout  time.Duration
	HttpReadTimeout  time.Duration
	HttpWriteTimeout time.Duration

	LogLevel slog.Level
}

func NewConfig

func NewConfig() (*Config, error)

type GetCurrentTime

type GetCurrentTime func() time.Time

type HandlerOptions

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

type LoggingMiddleware

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

func NewLoggingMiddleware

func NewLoggingMiddleware(logger *slog.Logger, next http.Handler) *LoggingMiddleware

func (*LoggingMiddleware) ServeHTTP

func (h *LoggingMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MemoryCache

type MemoryCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMemoryCache

func NewMemoryCache(capacity, maxItemSize int) *MemoryCache

func (*MemoryCache) Get

func (c *MemoryCache) Get(key CacheKey) ([]byte, bool)

func (*MemoryCache) Set

func (c *MemoryCache) Set(key CacheKey, value []byte, expiresAt time.Time)

type MemoryCacheEntry

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

type MemoryCacheEntryMap

type MemoryCacheEntryMap map[CacheKey]*MemoryCacheEntry

type MemoryCacheKeyList

type MemoryCacheKeyList []CacheKey

type SendfileHandler

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

func NewSendfileHandler

func NewSendfileHandler(enabled bool, next http.Handler) *SendfileHandler

func (*SendfileHandler) ServeHTTP

func (h *SendfileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server

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

func NewServer

func NewServer(config *Config, handler http.Handler) *Server

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop()

type Service

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

func NewService

func NewService(config *Config) *Service

func (*Service) Run

func (s *Service) Run() int

type UpstreamProcess

type UpstreamProcess struct {
	Started chan struct{}
	// contains filtered or unexported fields
}

func NewUpstreamProcess

func NewUpstreamProcess(name string, arg ...string) *UpstreamProcess

func (*UpstreamProcess) Run

func (p *UpstreamProcess) Run() (int, error)

func (*UpstreamProcess) Signal

func (p *UpstreamProcess) Signal(sig os.Signal) error

type Variant added in v0.0.2

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

func NewVariant added in v0.0.2

func NewVariant(r *http.Request) *Variant

func (*Variant) CacheKey added in v0.0.2

func (v *Variant) CacheKey() CacheKey

func (*Variant) Matches added in v0.0.2

func (v *Variant) Matches(responseHeader http.Header) bool

func (*Variant) SetResponseHeader added in v0.0.2

func (v *Variant) SetResponseHeader(header http.Header)

func (*Variant) VariantHeader added in v0.0.2

func (v *Variant) VariantHeader() http.Header

Jump to

Keyboard shortcuts

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