corehttp

package
v0.0.0-...-c18dace Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderServer        = "Server"
	HeaderXRequestId    = "X-Request-Id"
	HeaderContentType   = "Content-Type"
	HeaderUpgrade       = "Upgrade"
	HeaderUserAgent     = "User-Agent"
	HeaderXForwardedFor = "X-Forwarded-For"
	HeaderXRealIP       = "X-Real-IP"
	HeaderCacheControl  = "Cache-Control"

	ValueNotFound            = "Not found"
	ValueInternalServerError = "Internal server error"
	ValueAccessDenied        = "Access denied"
	ValueTextPlain           = "text/plain; charset=utf-8"
	ValueTextHTML            = "text/html; charset=utf-8"
	ValueAppJSON             = "application/json; charset=utf-8"

	SchemeSecure   = "https"
	SchemeInsecure = "http"
)

Variables

This section is empty.

Functions

func GetRequestContext

func GetRequestContext(rctx Context) (*edgepb.Context, bool)

GetRequestContext returns the context value.

func GetRequestTime

func GetRequestTime(ctx context.Context) time.Time

func SetRequestTime

func SetRequestTime(ctx context.Context) context.Context

Types

type Context

type Context interface {
	RequestContext
	ResponseWriter
	Unwrap() any

	Extra() *edgepb.Context
	SetExtra(x *edgepb.Context)

	Upgrade() (*websocket.Conn, error)
	Render(statusCode int, component templ.Component) error
	RequestBodyStream() io.Reader
	VisitRequestHeaders(visitor func(k, v []byte))
	VisitResponseHeaders(visitor func(k, v []byte))
}

func SetRequestContext

func SetRequestContext(ctx Context, msg *edgepb.Context) Context

SetRequestContext returns a new context with the given message

type RequestContext

type RequestContext interface {
	Context() context.Context
	Headers() map[string]string
	Queries() map[string][]string
	Query(k string) string
	QueryStr() string
	Header(k string) string
	Path() string
	URI() string
	Body() []byte
	JA4() string
	TLS() bool
	Method() string
	Host() string
	StatusCode() int
	Protocol() string
	Scheme() string
	RemoteAddr() string
	RequestIP() string
	RequestId() string
	RequestTime() time.Time

	SetHeader(key, value string)
	SetQuery(key string, values ...string)
	SetPath(p string)
	SetURI(u string)
	SetBody(b []byte)
	SetRequestId(id string)
	SetRequestIP(ip string)
	SetJA4(fingerprint string)
	SetMethod(m string)
	SetHost(h string)
	SetStatusCode(code int)
	SetProtocol(p string)
	SetRemoteAddr(addr string)
}

type RequestHandler

type RequestHandler func(Context) error

type ResponseWriter

type ResponseWriter interface {
	ResponseHeader() map[string]string
	ResponseBody() []byte

	SetResponseHeader(key, value string)
	AddResponseHeader(key, value string)
	ResetResponse()

	String(statusCode int, msg string) 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 SentinezContextKey

type SentinezContextKey string

SentinezContextKey is the key type for the context.

const (
	RequestHTTPCtxKey  SentinezContextKey = "senz.ctx.request.http"
	RequestHTTPTimeKey SentinezContextKey = "senz.ctx.request.time"
)

type Server

type Server interface {
	Shutdown(ctx context.Context) error
	ListenAndServe(addr string) error
	Use(mdw ...func(next RequestHandler) RequestHandler)
	Handle(fn RequestHandler)
	ListenAndServeTLS(addr, certFile, keyFile string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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