Documentation
¶
Index ¶
- func BadRequest(ctx Context) error
- func Challenge(ctx Context, challenge string, difficulty int, action string) error
- func Cookie(req Request, name string) (string, bool)
- func Forbidden(ctx Context) error
- func ForbiddenPage(requestId string) templ.Component
- func InternalServerError(ctx Context) error
- func NotFound(ctx Context) error
- func StripPort(addr []byte) []byte
- func TooManyRequests(ctx Context) error
- func Upstream2Target(upstream *edgepb.Upstream) (string, error)
- type BaseContext
- type Context
- type Option
- type Request
- type RequestContext
- type RequestHandler
- type ResponseWriter
- type ReverseProxy
- type Server
- type ServerOption
- func WithCertificate(certFile, certKeyFile string) ServerOption
- func WithOnQuicConnect(fn func(context.Context, *quic.Conn) context.Context) ServerOption
- func WithOnStdConnect(fn func(context.Context, net.Conn) context.Context) ServerOption
- func WithQuicListener(ln http3.QUICListener) ServerOption
- func WithServerName(name []byte) ServerOption
- func WithStdListener(ln net.Listener) ServerOption
- func WithTLSConfig(conf *tls.Config) ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func Challenge ¶
Challenge writes the proof-of-work page: the client solves challenge at difficulty (see szcrypto/pow) and posts the nonce to action.
func ForbiddenPage ¶
ForbiddenPage returns the HTML 403 page for the request requestId.
func InternalServerError ¶
func StripPort ¶
StripPort returns the host of addr without its port: "1.2.3.4:80" and "[::1]:80" give "1.2.3.4" and "::1", while a bare IPv4 or IPv6 address is returned as is. It slices addr, without allocating, and leaves the spaces around it.
func TooManyRequests ¶
Types ¶
type BaseContext ¶
type BaseContext struct {
// contains filtered or unexported fields
}
func (*BaseContext) RequestId ¶
func (b *BaseContext) RequestId() string
RequestId implements RequestContext.
func (*BaseContext) Reset ¶
func (b *BaseContext) Reset()
func (*BaseContext) ResourceId ¶
func (b *BaseContext) ResourceId() string
ResourceId implements RequestContext.
func (*BaseContext) SetRequestId ¶
func (b *BaseContext) SetRequestId(id string)
SetRequestId implements RequestContext.
func (*BaseContext) SetResourceId ¶
func (b *BaseContext) SetResourceId(id string)
SetResourceId implements RequestContext.
func (*BaseContext) SetTenantId ¶
func (b *BaseContext) SetTenantId(id string)
SetTenantId implements RequestContext.
func (*BaseContext) TenantId ¶
func (b *BaseContext) TenantId() string
TenantId implements RequestContext.
type Context ¶
type Context interface {
RequestContext
Request
ResponseWriter
Unwrap() any
X() *edgepb.ContextExtra
Render(statusCode int, component templ.Component) error
RequestBodyStream() io.Reader
VisitRequestHeaders(visitor func(k, v []byte))
VisitResponseHeaders(visitor func(k, v []byte))
}
type Option ¶
type Option struct {
CertFile string
CertKeyFile string
TLSConfig *tls.Config
ServerName []byte
OnStdConnect func(context.Context, net.Conn) context.Context
StdListener net.Listener
OnQuicConnect func(context.Context, *quic.Conn) context.Context
QuicListener http3.QUICListener
}
func NewOption ¶
func NewOption(opts ...ServerOption) *Option
type Request ¶
type Request interface {
Context() context.Context
Headers() map[string][][]byte
Queries() map[string][][]byte
Query(k []byte) []byte
QueryStr() []byte
Header(k []byte) []byte
Path() []byte
URI() []byte
Body() []byte
JA4() string
TLS() bool
Method() []byte
Host() []byte
StatusCode() int
Protocol() string
Scheme() string
RemoteAddr() []byte
RequestIP() []byte
RequestTime() time.Time
SetHeader(key, value []byte)
SetQuery(key []byte, values ...[]byte)
SetPath(p []byte)
SetURI(u []byte)
SetBody(b []byte)
SetStatusCode(code int)
SetHost(h []byte)
}
type RequestContext ¶
type RequestHandler ¶
type ResponseWriter ¶
type ResponseWriter interface {
ResponseHeader() map[string][][]byte
ResponseBody() []byte
SetResponseHeader(key, value []byte)
AddResponseHeader(key, value []byte)
ResetResponse()
String(statusCode int, msg []byte) error
JSON(statusCode int, body []byte) error
File(path string) error
Flush() error
Copy(src io.Reader) error
}
type ReverseProxy ¶
type ReverseProxy interface {
Serve(ctx Context)
}
type Server ¶
type Server interface {
Shutdown(ctx context.Context) error
ListenAndServe(addr string, opts ...ServerOption) error
Use(mdw ...func(next RequestHandler) RequestHandler)
Handle(fn RequestHandler)
AcceptReverse(target string) (ReverseProxy, error)
}
type ServerOption ¶
type ServerOption func(opt *Option)
func WithCertificate ¶
func WithCertificate(certFile, certKeyFile string) ServerOption
func WithOnQuicConnect ¶
func WithOnStdConnect ¶
func WithQuicListener ¶
func WithQuicListener(ln http3.QUICListener) ServerOption
func WithServerName ¶
func WithServerName(name []byte) ServerOption
func WithStdListener ¶
func WithStdListener(ln net.Listener) ServerOption
func WithTLSConfig ¶
func WithTLSConfig(conf *tls.Config) ServerOption