Help us shape the future of Go! Take the 2026 Go Developer Survey

szhttp

package
v0.0.0-...-76879de Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(ctx Context) error

func Challenge

func Challenge(
	ctx Context, challenge string, difficulty int, action string,
) error

Challenge writes the proof-of-work page: the client solves challenge at difficulty (see szcrypto/pow) and posts the nonce to action.

func Cookie(req Request, name string) (string, bool)

Cookie returns the value of the named request cookie.

func Forbidden

func Forbidden(ctx Context) error

func ForbiddenPage

func ForbiddenPage(requestId string) templ.Component

ForbiddenPage returns the HTML 403 page for the request requestId.

func InternalServerError

func InternalServerError(ctx Context) error

func NotFound

func NotFound(ctx Context) error

func StripPort

func StripPort(addr []byte) []byte

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

func TooManyRequests(ctx Context) error

func Upstream2Target

func Upstream2Target(upstream *edgepb.Upstream) (string, error)

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 RequestContext interface {
	RequestId() string
	SetRequestId(id string)

	ResourceId() string
	SetResourceId(id string)

	TenantId() string
	SetTenantId(id string)
}

type RequestHandler

type RequestHandler func(Context) error

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)
}

func DecoreServer

func DecoreServer(conf *settingpb.Config, s Server) Server

type ServerOption

type ServerOption func(opt *Option)

func WithCertificate

func WithCertificate(certFile, certKeyFile string) ServerOption

func WithOnQuicConnect

func WithOnQuicConnect(
	fn func(context.Context, *quic.Conn) context.Context) ServerOption

func WithOnStdConnect

func WithOnStdConnect(
	fn func(context.Context, net.Conn) context.Context) ServerOption

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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