Documentation ¶
Index ¶
- Constants
- Variables
- func CleanPath(s string) string
- func EnforceRateReq(r *http.Request, l rate.Limit) http.Handler
- func Error(w http.ResponseWriter, r *http.Request, code int, explanation ...string)
- func ForEachSession(f func(*ClientSession) bool)
- func GetClientMetrics() (metrics map[string]ClientMetrics)
- func NormalPath(s string) string
- func NumClients() int
- func ParseErrorTemplates(fs fs.FS, prefix string) (*template.Template, error)
- func RegisterSwitchVariable(v SwitchVariable)
- func RelativePath(root, rel string) string
- func ResolveNatsFromContext(ctx context.Context) *enats.Client
- func StartInternalRequest(r *http.Request) (rctx *http.Request)
- func WithStateResolver(ctx context.Context, r StateResolver) context.Context
- type BufferedResponse
- type CertProvider
- type ClientMetrics
- type ClientSession
- func (s *ClientSession) BlockFor(d time.Duration) time.Time
- func (s *ClientSession) BlockUntil(t time.Time) time.Time
- func (s *ClientSession) EnforceRateReq(c context.Context, r *http.Request, l rate.Limit) http.Handler
- func (s *ClientSession) FirstRequest() time.Time
- func (s *ClientSession) IsBlocked() bool
- func (s *ClientSession) LastRequest() time.Time
- func (s *ClientSession) Metrics() ClientMetrics
- func (s *ClientSession) SetOnContext(ctx context.Context) context.Context
- func (s *ClientSession) Unblock()
- type ConditionalResponse
- func (cr *ConditionalResponse) Header() http.Header
- func (cr *ConditionalResponse) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (cr *ConditionalResponse) Unwrap() http.ResponseWriter
- func (cr *ConditionalResponse) Write(b []byte) (int, error)
- func (cr *ConditionalResponse) WriteHeader(status int)
- type ErrorPageParams
- type ErrorPageType
- type HandleMux
- type HandlePublish
- type HandleService
- type HandleSwitch
- type Handler
- type HandlerFunc
- type InternalHandler
- func (i InternalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
- func (i InternalHandler) String() string
- func (i *InternalHandler) UnmarshalInline(text string) error
- func (i *InternalHandler) UnmarshalText(text []byte) error
- func (i *InternalHandler) UnmarshalYAML(node *yaml.Node) (err error)
- type Mux
- type Pattern
- func (p Pattern) IsWildcard() bool
- func (p Pattern) MarshalJSON() ([]byte, error)
- func (p Pattern) MarshalText() ([]byte, error)
- func (p Pattern) MarshalYAML() (any, error)
- func (p *Pattern) Match(host, path string) bool
- func (p Pattern) String() string
- func (p *Pattern) UnmarshalJSON(data []byte) (err error)
- func (p *Pattern) UnmarshalText(data []byte) (e error)
- func (p *Pattern) UnmarshalYAML(node *yaml.Node) (err error)
- type RateLimitHandler
- type Result
- type RewriteHandler
- func (rh RewriteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
- func (rh RewriteHandler) String() string
- func (rh *RewriteHandler) UnmarshalInline(text string) error
- func (rh *RewriteHandler) UnmarshalText(text []byte) error
- func (rh *RewriteHandler) UnmarshalYAML(node *yaml.Node) (err error)
- type Server
- func (s *Server) Close() error
- func (s *Server) GetIPInfoProvider() netx.IPInfoProvider
- func (s *Server) Listen() (err error)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) ServeHTTPSession(w http.ResponseWriter, r *http.Request, session *ClientSession)
- func (s *Server) SetErrorTemplates(t *template.Template)
- func (s *Server) SetHosts(vhosts ...*VirtualHost)
- func (s *Server) SetIPInfoProvider(provider netx.IPInfoProvider)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Value(key any) any
- func (s *Server) Wait()
- type StateResolver
- type Subhandler
- type SwitchVariable
- type TopLevelMux
- type VirtualHost
- type VirtualHostOptions
Constants ¶
View Source
const ( StatusSessionError = 522 StatusUpstreamError = 1020 StatusWSFBlocked = 1021 StatusMaintenance = 1022 StatusRestartLoop = 1023 StatusPanic = 1024 StatusSignatureError = 1025 StatusPublishError = 1026 )
Variables ¶
View Source
var LocalClientSession = &ClientSession{ IP: netx.ParseIP("127.0.0.1"), IPHash: 0x7f000001, RemoteAddr: "127.0.0.1:0", IPInfo: netx.LocalIPInfoHeaders, Local: true, }
View Source
var Raygen = ray.NewGenerator(config.Get().Host)
View Source
var Registry = variant.NewRegistry[Handler]()
Functions ¶
func ForEachSession ¶
func ForEachSession(f func(*ClientSession) bool)
func GetClientMetrics ¶
func GetClientMetrics() (metrics map[string]ClientMetrics)
func NormalPath ¶
func NumClients ¶
func NumClients() int
func ParseErrorTemplates ¶
func RegisterSwitchVariable ¶
func RegisterSwitchVariable(v SwitchVariable)
func RelativePath ¶
func WithStateResolver ¶
func WithStateResolver(ctx context.Context, r StateResolver) context.Context
Types ¶
type BufferedResponse ¶
func NewBufferedResponse ¶
func NewBufferedResponse(buf *bytes.Buffer) *BufferedResponse
func (*BufferedResponse) Header ¶
func (bw *BufferedResponse) Header() http.Header
func (*BufferedResponse) Response ¶
func (bw *BufferedResponse) Response() *http.Response
func (*BufferedResponse) ServeHTTP ¶
func (bw *BufferedResponse) ServeHTTP(w http.ResponseWriter, r *http.Request)
Serves the buffered response to another writer.
func (*BufferedResponse) WriteHeader ¶
func (bw *BufferedResponse) WriteHeader(status int)
type CertProvider ¶ added in v0.3.5
type CertProvider struct { CertPath string `yaml:"cert,omitempty"` // Path to the TLS certificate. KeyPath string `yaml:"key,omitempty"` // Path to the TLS key. // contains filtered or unexported fields }
func (*CertProvider) GetCertificate ¶ added in v0.3.5
func (cp *CertProvider) GetCertificate(chi *tls.ClientHelloInfo) (cert *tls.Certificate, err error)
type ClientMetrics ¶
type ClientSession ¶
type ClientSession struct { IP netx.IP IPHash uint32 RemoteAddr string // ip:0, for setting request.RemoteAddr Values sync.Map // For handler's use. NumRequests atomic.Int32 BlockedUntilMs atomic.Int64 IPInfo http.Header Local bool // contains filtered or unexported fields }
func ClientSessionFromContext ¶
func ClientSessionFromContext(ctx context.Context) (session *ClientSession)
func GetClientSession ¶
func GetClientSession(ip netx.IP) (session *ClientSession)
func StartClientRequest ¶
func StartClientRequest(r *http.Request, infoProvider netx.IPInfoProvider) (rctx *http.Request, session *ClientSession)
func (*ClientSession) BlockUntil ¶
func (s *ClientSession) BlockUntil(t time.Time) time.Time
func (*ClientSession) EnforceRateReq ¶
func (*ClientSession) FirstRequest ¶
func (s *ClientSession) FirstRequest() time.Time
func (*ClientSession) IsBlocked ¶
func (s *ClientSession) IsBlocked() bool
func (*ClientSession) LastRequest ¶
func (s *ClientSession) LastRequest() time.Time
func (*ClientSession) Metrics ¶
func (s *ClientSession) Metrics() ClientMetrics
func (*ClientSession) SetOnContext ¶
func (s *ClientSession) SetOnContext(ctx context.Context) context.Context
func (*ClientSession) Unblock ¶
func (s *ClientSession) Unblock()
type ConditionalResponse ¶
type ConditionalResponse struct { Touched bool // contains filtered or unexported fields }
func NewConditionalResponse ¶
func NewConditionalResponse(rw http.ResponseWriter) *ConditionalResponse
func (*ConditionalResponse) Header ¶
func (cr *ConditionalResponse) Header() http.Header
func (*ConditionalResponse) Hijack ¶
func (cr *ConditionalResponse) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*ConditionalResponse) Unwrap ¶
func (cr *ConditionalResponse) Unwrap() http.ResponseWriter
func (*ConditionalResponse) WriteHeader ¶
func (cr *ConditionalResponse) WriteHeader(status int)
type ErrorPageParams ¶
type ErrorPageParams struct { Template string StatusSent int // Status code to send if non-zero Code int // Error code, or http status code Title string // Title of the error page Explanation string // Explanation of the error Solution string // Solution to the error Server string // Server name Host string // Host name Date string // Date Ray string // Ray ID IP string // Client IP Type ErrorPageType // Type of error page }
func (*ErrorPageParams) WithRequest ¶
func (params *ErrorPageParams) WithRequest(r *http.Request) *ErrorPageParams
func (*ErrorPageParams) WriteTo ¶
func (params *ErrorPageParams) WriteTo(w http.ResponseWriter, sv *Server) (err error)
type ErrorPageType ¶
type ErrorPageType uint8
const ( ErrorPageAny ErrorPageType = iota ErrorPageHTML ErrorPageHead ErrorPagePlain ErrorPageJSON )
type HandlePublish ¶
type HandlePublish struct {
// contains filtered or unexported fields
}
func (HandlePublish) ServeHTTP ¶
func (h HandlePublish) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
func (HandlePublish) String ¶
func (h HandlePublish) String() string
func (*HandlePublish) UnmarshalInline ¶
func (h *HandlePublish) UnmarshalInline(text string) error
func (*HandlePublish) UnmarshalText ¶
func (h *HandlePublish) UnmarshalText(text []byte) error
type HandleService ¶
type HandleService struct {
// contains filtered or unexported fields
}
func (HandleService) ServeHTTP ¶
func (h HandleService) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
func (HandleService) String ¶
func (h HandleService) String() string
func (*HandleService) UnmarshalInline ¶
func (h *HandleService) UnmarshalInline(text string) error
func (*HandleService) UnmarshalText ¶
func (h *HandleService) UnmarshalText(text []byte) error
type HandleSwitch ¶
type HandleSwitch struct { Mux Variable SwitchVariable }
func (*HandleSwitch) ServeHTTP ¶
func (h *HandleSwitch) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
func (*HandleSwitch) String ¶
func (h *HandleSwitch) String() string
func (*HandleSwitch) UnmarshalYAML ¶
func (h *HandleSwitch) UnmarshalYAML(node *yaml.Node) (e error)
type HandlerFunc ¶ added in v0.3.2
type HandlerFunc func(w http.ResponseWriter, r *http.Request) Result
func (HandlerFunc) ServeHTTP ¶ added in v0.3.2
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
func (HandlerFunc) String ¶ added in v0.3.2
func (f HandlerFunc) String() string
type InternalHandler ¶
type InternalHandler struct {
Inner Subhandler
}
func (InternalHandler) ServeHTTP ¶
func (i InternalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
func (InternalHandler) String ¶
func (i InternalHandler) String() string
func (*InternalHandler) UnmarshalInline ¶
func (i *InternalHandler) UnmarshalInline(text string) error
func (*InternalHandler) UnmarshalText ¶
func (i *InternalHandler) UnmarshalText(text []byte) error
func (*InternalHandler) UnmarshalYAML ¶
func (i *InternalHandler) UnmarshalYAML(node *yaml.Node) (err error)
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
func NewExactPattern ¶
func NewPattern ¶
func (Pattern) IsWildcard ¶
func (Pattern) MarshalJSON ¶
func (Pattern) MarshalText ¶
func (Pattern) MarshalYAML ¶
func (*Pattern) UnmarshalJSON ¶
func (*Pattern) UnmarshalText ¶
func (*Pattern) UnmarshalYAML ¶
type RateLimitHandler ¶
func (RateLimitHandler) ServeHTTP ¶
func (rh RateLimitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
func (RateLimitHandler) String ¶
func (rh RateLimitHandler) String() string
func (*RateLimitHandler) UnmarshalInline ¶
func (rh *RateLimitHandler) UnmarshalInline(text string) error
type RewriteHandler ¶
func (RewriteHandler) ServeHTTP ¶
func (rh RewriteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) Result
func (RewriteHandler) String ¶
func (rh RewriteHandler) String() string
func (*RewriteHandler) UnmarshalInline ¶
func (rh *RewriteHandler) UnmarshalInline(text string) error
func (*RewriteHandler) UnmarshalText ¶
func (rh *RewriteHandler) UnmarshalText(text []byte) error
func (*RewriteHandler) UnmarshalYAML ¶
func (rh *RewriteHandler) UnmarshalYAML(node *yaml.Node) (err error)
type Server ¶
type Server struct { context.Context Server http.Server TopLevelMux Signer *urlsigner.Signer // contains filtered or unexported fields }
func GetServerFromContext ¶
func (*Server) GetIPInfoProvider ¶
func (s *Server) GetIPInfoProvider() netx.IPInfoProvider
func (*Server) ServeHTTPSession ¶
func (s *Server) ServeHTTPSession(w http.ResponseWriter, r *http.Request, session *ClientSession)
ServeHTTP implements http.Handler.
func (*Server) SetErrorTemplates ¶
func (*Server) SetHosts ¶
func (s *Server) SetHosts(vhosts ...*VirtualHost)
func (*Server) SetIPInfoProvider ¶
func (s *Server) SetIPInfoProvider(provider netx.IPInfoProvider)
type StateResolver ¶
func StateResolverFromContext ¶
func StateResolverFromContext(ctx context.Context) StateResolver
type Subhandler ¶
type Subhandler struct {
Handler
}
func (*Subhandler) UnmarshalYAML ¶
func (t *Subhandler) UnmarshalYAML(node *yaml.Node) (e error)
type SwitchVariable ¶
func RegisterSwitchVariableFunc ¶
func RegisterSwitchVariableFunc(name string, f func(r *http.Request) string) SwitchVariable
type TopLevelMux ¶
type TopLevelMux struct {
// contains filtered or unexported fields
}
func (*TopLevelMux) GetCertificate ¶
func (mux *TopLevelMux) GetCertificate(chi *tls.ClientHelloInfo) (cert *tls.Certificate, err error)
GetCertificate implements tls.Config.GetCertificate.
func (*TopLevelMux) Hostnames ¶
func (mux *TopLevelMux) Hostnames() (hostnames []string)
Hostnames returns a list of all hostnames in the mux.
func (*TopLevelMux) SetHosts ¶
func (mux *TopLevelMux) SetHosts(vhosts ...*VirtualHost)
Replaces virtual hosts in bulk.
type VirtualHost ¶
type VirtualHost struct { VirtualHostOptions Mux }
func NewVirtualHost ¶
func NewVirtualHost(opt VirtualHostOptions) (vh *VirtualHost)
type VirtualHostOptions ¶
type VirtualHostOptions struct { Hostnames []string `yaml:"-"` NoUpgrade bool `yaml:"no_upgrade,omitempty"` // Do not upgrade HTTP to HTTPS. Certs map[string]*CertProvider `yaml:"certs,omitempty"` // TLS certificates. }
Click to show internal directories.
Click to hide internal directories.