core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EdgeRuntime

type EdgeRuntime interface {
	// Execute starts VCL request lifecycle.
	Execute(context.Context) error

	// CreateBackendRequest is hook point of making bereq from req
	// This hook will be called before calling vcl_pass or vcl_miss
	// Must return raw headers of BackendRequest
	CreateBackendRequest() vintage.RawHeader

	// CreateBackendRequest is hook point of making resp from beresp
	// This hook will be called before calling vcl_deliver
	// Must return raw headers of ClientResponse
	CreateClientResponse() (vintage.RawHeader, error)

	// CreateObjectResponse is hool poing of construct object response.
	// This hook will be called before calling vcl_error.
	// VCL may call without request proxying like "error 400" statement,
	// then object (backend response) is nil, so runtime have to construct from empty.
	// First argument is status code that is set via error [statusCode]
	// Second argument is response body that is set via error [statusCode] [response]
	CreateObjectResponse(int, string) (vintage.RawHeader, error)

	// Proxy is hook point for actual senging origin request.
	// This hook will be called before calling vcl_fetch
	// Must return raw headers of BackendResponse
	Proxy(ctx context.Context, backendName string) (vintage.RawHeader, error)

	// WriteResponse is hook point for sending client response.
	// This hook will be called before calling vcl_log
	// the response is exact 3 length of in64 slice:
	// 0. written header bytes
	// 1. written body bytes
	// 2. written response bytes (include status line)
	WriteResponse() ([3]int64, error)
}
type Header struct {
	MH textproto.MIMEHeader
}

func NewHeader

func NewHeader(h map[string][]string) *Header

func (*Header) Add

func (h *Header) Add(key, value string)

func (*Header) DeleteSetCookie

func (h *Header) DeleteSetCookie(name string) bool

Used for setcookie.delete_by_name()

func (*Header) Get

func (h *Header) Get(key string) string

func (*Header) GetSetCookie

func (h *Header) GetSetCookie(name string) string

Used for setcookie.get_value_by_name()

func (*Header) Set

func (h *Header) Set(key, value string)

func (*Header) Unset

func (h *Header) Unset(key string)

type Resource

type Resource[T EdgeRuntime] func(c *Runtime[T])

func AclResource

func AclResource[T EdgeRuntime](name string, v *vintage.Acl) Resource[T]

func BackendResource

func BackendResource[T EdgeRuntime](name string, v *vintage.Backend) Resource[T]

func LoggingResource

func LoggingResource[T EdgeRuntime](name string, v *vintage.LoggingEndpoint) Resource[T]

func SubroutineResource

func SubroutineResource[T EdgeRuntime](name string, v Subroutine[T]) Resource[T]

func TableResource

func TableResource[T EdgeRuntime](name string, v *vintage.Table) Resource[T]

type Runtime

type Runtime[T EdgeRuntime] struct {
	Backend               *vintage.Backend
	RequestHeader         *Header
	BackendRequestHeader  *Header
	BackendResponseHeader *Header
	ResponseHeader        *Header
	RequestStartTime      time.Time
	RequestEndTime        time.Time
	Restarts              int
	RequestHash           string
	RequestHeaderBytes    int64

	ClientIp       net.IP
	ClientIdentity string

	// We should implement User-Agent related matcher by ourselves
	UserAgent *UserAgent
	// Temporal WAF related variables
	Waf *Waf

	// Declaration stacks
	Backends         map[string]*vintage.Backend
	Acls             map[string]*vintage.Acl
	Tables           map[string]*vintage.Table
	Subroutines      map[string]Subroutine[T]
	LoggingEndpoints map[string]*vintage.LoggingEndpoint

	// Properties that will be assigned in the process
	OriginalHost                        string
	MaxStaleIfError                     time.Duration
	MaxStaleWhileRevalidate             time.Duration
	ClientSocketCongestionAlgorithm     string
	ClientSocketCWND                    int64
	ClientSocketPace                    int64
	EsiAllowInsideData                  bool
	EnableESI                           bool
	ESILevel                            int64
	IsLocallyGenerated                  bool
	TimeToFirstByte                     time.Duration
	BackendResponseBrotli               bool
	BackendResponseCachable             bool
	BackendResponseDoESI                bool
	BackendResponseDoStream             bool
	BackendResponseGrace                bool
	BackendResponseGzip                 bool
	BackendResponseHipaa                bool
	BackendResponsePCI                  bool
	BackendResponseStaleIfError         time.Duration
	BackendResponseStaleWhileRevalidate time.Duration
	BackendResponseTTL                  time.Duration
	ObjectStaleIfError                  time.Duration
	ObjectStaleWhileRevalidate          time.Duration
	ObjectTTL                           time.Duration
	ObjectStatus                        int64
	ObjectResponse                      string
	EnableRangeOnPass                   bool
	EnableSegmentedCaching              bool
	HashAlwaysMiss                      bool
	HashIgnoreBusy                      bool
	ResponseBytesWritten                int64
	ResponseBodyBytesWritten            int64
	ResponseHeaderBytesWritten          int64
	GeoIpOverride                       string
	GeoIpUseXForwardedFor               bool
	SegmentedCachingBlockSize           int64
	SaintMode                           bool
	ResponseStale                       bool
	ResponseStaleIsError                bool
	ResponseStaleIsRevalidating         bool
	ResponseCompleted                   bool

	// Following fields are set via builtin function
	FastlyError               string
	DisableCompressionHeaders []string
	PushResources             []string
	H3AltSvc                  bool
}

func NewRuntime

func NewRuntime[T EdgeRuntime](r map[string][]string, resources ...Resource[T]) *Runtime[T]

func (*Runtime[T]) Cleanup

func (c *Runtime[T]) Cleanup()

func (*Runtime[T]) GetClientIdentity

func (c *Runtime[T]) GetClientIdentity() string

Used for client.identity

func (*Runtime[T]) Lifecycle

func (c *Runtime[T]) Lifecycle(ctx context.Context, r T) error

Lifecycle starts from RECV directive.

func (*Runtime[T]) RegexpMatch

func (c *Runtime[T]) RegexpMatch(src, dst string) (bool, error)

func (*Runtime[T]) Register

func (c *Runtime[T]) Register(resources ...Resource[T])

func (*Runtime[T]) RequestDigest

func (c *Runtime[T]) RequestDigest() string

Used for req.digest

func (*Runtime[T]) RequestRangeHeader

func (c *Runtime[T]) RequestRangeHeader(mode string) (int64, error)

type SameSite

type SameSite int

SameSite allows a server to define a cookie attribute making it impossible for the browser to send this cookie along with cross-site requests. The main goal is to mitigate the risk of cross-origin information leakage, and provide some protection against cross-site request forgery attacks.

See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details.

const (
	SameSiteDefaultMode SameSite = iota + 1
	SameSiteLaxMode
	SameSiteStrictMode
	SameSiteNoneMode
)

type Subroutine

type Subroutine[T EdgeRuntime] func(ctx T) (vintage.State, error)

type UserAgent

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

UserAgent struct wraps uasurfer library and returns User-Agent related values. Currently we truct this package but we should implement some or more features in the future, The we could replace this library without changing method interfaces.

func NewUserAgent

func NewUserAgent(ua string) *UserAgent

func (*UserAgent) BotName

func (u *UserAgent) BotName() string

used for client.bot.name

func (*UserAgent) BrowserName

func (u *UserAgent) BrowserName() string

used for client.browser.name

func (*UserAgent) BrowserVersion

func (u *UserAgent) BrowserVersion() string

used for client.browser.version

func (*UserAgent) IsBot

func (u *UserAgent) IsBot() bool

used for client.class.bot

func (*UserAgent) IsBrowser

func (u *UserAgent) IsBrowser() bool

used for client.class.browser

func (*UserAgent) IsEReader

func (u *UserAgent) IsEReader() bool

used for client.platform.ereader

func (*UserAgent) IsGameConsole

func (u *UserAgent) IsGameConsole() bool

used for client.platform.gameconsole

func (*UserAgent) IsMobile

func (u *UserAgent) IsMobile() bool

used for client.platform.mobile

func (*UserAgent) IsSmartTV

func (u *UserAgent) IsSmartTV() bool

used for client.platform.smarttv

func (*UserAgent) IsTablet

func (u *UserAgent) IsTablet() bool

used for client.platform.tablet

func (*UserAgent) IsTouchScreen

func (u *UserAgent) IsTouchScreen() bool

used for client.display.touchscreen

func (*UserAgent) IsTvPlayer

func (u *UserAgent) IsTvPlayer() bool

used for client.platform.tvplayer

func (*UserAgent) OSName

func (u *UserAgent) OSName() string

used for client.os.name

func (*UserAgent) OSVersion

func (u *UserAgent) OSVersion() string

used for client.os.version

type Waf

type Waf struct {
	AnomalyScore         int64
	Blocked              bool
	Counter              int64
	Executed             bool
	Failures             int64
	HttpViolationScore   int64
	InboundAnomalyScore  int64
	LFIScore             int64
	Logdata              string
	Logged               bool
	Message              string
	Passed               bool
	PHPInjectionScore    int64
	RCEScore             int64
	RFIScore             int64
	RuleId               int64
	SessionFixationScore int64
	SQLInjectionScore    int64
	Severity             int64
	XSSScore             int64
}

Currently Edge runtime does not support WAF Can be set and get but always returns zero value or set value

Jump to

Keyboard shortcuts

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