api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Log API family. Note that the Envoy's log level can be changed at runtime.
	LogTrace     = api.LogTrace
	LogDebug     = api.LogDebug
	LogInfo      = api.LogInfo
	LogWarn      = api.LogWarn
	LogError     = api.LogError
	LogCritical  = api.LogCritical
	LogTracef    = api.LogTracef
	LogDebugf    = api.LogDebugf
	LogInfof     = api.LogInfof
	LogWarnf     = api.LogWarnf
	LogErrorf    = api.LogErrorf
	LogCriticalf = api.LogCriticalf
	GetLogLevel  = api.GetLogLevel

	ErrInternalFailure      = api.ErrInternalFailure
	ErrSerializationFailure = api.ErrSerializationFailure
	ErrValueNotFound        = api.ErrValueNotFound
)

Functions

This section is empty.

Types

type BufferInstance

type BufferInstance = api.BufferInstance

type ConfigCallbackHandler

type ConfigCallbackHandler interface {
}

ConfigCallbackHandler provides API that is used during initializing configuration

type Consumer

type Consumer interface {
	Name() string
	PluginConfig(name string) PluginConsumerConfig
}

type DataBufferBase

type DataBufferBase = api.DataBufferBase

type DecodeWholeRequestFilter

type DecodeWholeRequestFilter interface {
	// DecodeRequest processes the whole request once when WaitAllData is returned
	// headers: the request header
	// data: the whole request body, nil if the request doesn't have body
	// trailers: TODO, just a placeholder
	DecodeRequest(headers RequestHeaderMap, data BufferInstance, trailers RequestTrailerMap) ResultAction
}

type DynamicMetadata

type DynamicMetadata = api.DynamicMetadata

DynamicMetadata operates the Envoy's dynamic metadata

type EncodeWholeResponseFilter

type EncodeWholeResponseFilter interface {
	// EncodeResponse processes the whole response once when WaitAllData is returned
	// headers: the response header
	// data: the whole response body, nil if the response doesn't have body
	// trailers: TODO, just a placeholder
	EncodeResponse(headers ResponseHeaderMap, data BufferInstance, trailers ResponseTrailerMap) ResultAction
}

type Filter

type Filter interface {

	// DecodeHeaders processes request headers. The endStream is true if the request doesn't have body
	DecodeHeaders(headers RequestHeaderMap, endStream bool) ResultAction
	// DecodeData might be called multiple times during handling the request body.
	// The endStream is true when handling the last piece of the body.
	DecodeData(data BufferInstance, endStream bool) ResultAction
	// TODO, just a placeholder. DecodeTrailers is not called yet
	DecodeTrailers(trailers RequestTrailerMap) ResultAction
	DecodeWholeRequestFilter

	// EncodeHeaders processes response headers. The endStream is true if the response doesn't have body
	EncodeHeaders(headers ResponseHeaderMap, endStream bool) ResultAction
	// EncodeData might be called multiple times during handling the response body.
	// The endStream is true when handling the last piece of the body.
	EncodeData(data BufferInstance, endStream bool) ResultAction
	// TODO, just a placeholder. EncodeTrailers is not called yet
	EncodeTrailers(trailers ResponseTrailerMap) ResultAction
	EncodeWholeResponseFilter

	// OnLog is called when the HTTP stream is ended on HTTP Connection Manager filter.
	OnLog()
}

Filter represents a collection of callbacks in which Envoy will call your Go code. Every filter method (except the OnLog) is run in goroutine so it's non-blocking. To know how do we run the Filter during request processing, please refer to https://github.com/mosn/htnn/blob/main/content/en/docs/developer-guide/plugin_development.md

type FilterCallbackHandler

type FilterCallbackHandler interface {
	// StreamInfo provides API to get/set current stream's context.
	StreamInfo() StreamInfo
	// RecoverPanic covers panic to 500 response to avoid crashing Envoy. If you create goroutine
	// in your Filter, please add `defer RecoverPanic()` to avoid crash by panic.
	RecoverPanic()
	// GetProperty fetch Envoy attribute and return the value as a string.
	// The list of attributes can be found in https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes.
	// If the fetch succeeded, a string will be returned.
	// If the value is a timestamp, it is returned as a timestamp string like "2023-07-31T07:21:40.695646+00:00".
	// If the fetch failed (including the value is not found), an error will be returned.
	//
	// The error can be one of:
	// * ErrInternalFailure
	// * ErrSerializationFailure (Currently, fetching attributes in List/Map type are unsupported)
	// * ErrValueNotFound
	GetProperty(key string) (string, error)

	// LookupConsumer is used in the Authn plugins to fetch the corresponding consumer, with
	// the plugin name and plugin specific key. We return a 'fat' Consumer so that additional
	// info like `Name` can be retrieved.
	LookupConsumer(pluginName, key string) (Consumer, bool)
	// SetConsumer is used in the Authn plugins to set the corresponding consumer after authentication.
	SetConsumer(c Consumer)
	GetConsumer() Consumer
}

FilterCallbackHandler provides API that is used during request processing

type FilterFactory

type FilterFactory func(config interface{}, callbacks FilterCallbackHandler) Filter

type FilterState

type FilterState = api.FilterState

FilterState operates the Envoy's filter state

type HeaderMap

type HeaderMap = api.HeaderMap

type IPAddress

type IPAddress struct {
	Address string
	IP      string
	Port    int
}

type LocalResponse

type LocalResponse struct {
	Code int
	// If the Msg is not empty, we will set the reply's body according to the Msg.
	// The rule to generate body is:
	// 1. If Content-Type is specified in the Header, the Msg will be sent directly.
	// 2. If the response header is received, and the Content-Type is "application/json", the Msg is wrapped into a JSON like `{"msg": $MSG}`.
	// 3. If the request doesn't have Content-Type or the Content-Type is "application/json", the Msg is wrapped into a JSON.
	// 4. Otherwise, the Msg will be sent directly.
	Msg    string
	Header http.Header
	// contains filtered or unexported fields
}

LocalResponse represents the reply sent directly to the client instead of using the upstream response. Return `&LocalResponse{Code: 4xx, ...}` in the method if you want to send such a reply.

func (*LocalResponse) OK

func (i *LocalResponse) OK()

type PassThroughFilter

type PassThroughFilter struct{}

func (*PassThroughFilter) DecodeData

func (f *PassThroughFilter) DecodeData(data BufferInstance, endStream bool) ResultAction

func (*PassThroughFilter) DecodeHeaders

func (f *PassThroughFilter) DecodeHeaders(headers RequestHeaderMap, endStream bool) ResultAction

func (*PassThroughFilter) DecodeRequest

func (f *PassThroughFilter) DecodeRequest(headers RequestHeaderMap, data BufferInstance, trailers RequestTrailerMap) ResultAction

func (*PassThroughFilter) DecodeTrailers

func (f *PassThroughFilter) DecodeTrailers(trailers RequestTrailerMap) ResultAction

func (*PassThroughFilter) EncodeData

func (f *PassThroughFilter) EncodeData(data BufferInstance, endStream bool) ResultAction

func (*PassThroughFilter) EncodeHeaders

func (f *PassThroughFilter) EncodeHeaders(headers ResponseHeaderMap, endStream bool) ResultAction

func (*PassThroughFilter) EncodeResponse

func (f *PassThroughFilter) EncodeResponse(headers ResponseHeaderMap, data BufferInstance, trailers ResponseTrailerMap) ResultAction

func (*PassThroughFilter) EncodeTrailers

func (f *PassThroughFilter) EncodeTrailers(trailers ResponseTrailerMap) ResultAction

func (*PassThroughFilter) OnLog

func (f *PassThroughFilter) OnLog()

type PluginConfig

type PluginConfig interface {
	ProtoReflect() protoreflect.Message
	Validate() error
}

type PluginConsumerConfig

type PluginConsumerConfig interface {
	PluginConfig
	Index() string
}

type RequestHeaderMap

type RequestHeaderMap interface {
	api.RequestHeaderMap

	// Url returns the parsed `url.URL`
	Url() *url.URL
	// Cookies returns the HTTP Cookies.
	// If multiple cookies match the given name, only one cookie will be returned.
	Cookies() map[string]*http.Cookie
}

type RequestTrailerMap

type RequestTrailerMap = api.RequestTrailerMap

type ResponseHeaderMap

type ResponseHeaderMap = api.ResponseHeaderMap

type ResponseTrailerMap

type ResponseTrailerMap = api.ResponseTrailerMap

type ResultAction

type ResultAction interface {
	OK()
}

ResultAction is the result returned by each Filter method

var (
	// Continue indicates the process can continue without steering
	Continue ResultAction = &isResultAction{typeid: 0}
	// WaitAllData controls if the request/response body needs to be fully buffered during processing by Go plugin.
	// If this action is returned, DecodeData/EncodeData will be called by DecodeRequest/EncodeResponse.
	WaitAllData ResultAction = &isResultAction{typeid: 1}
)

type StreamInfo

type StreamInfo interface {
	GetRouteName() string
	FilterChainName() string
	// Protocol return the request's protocol.
	Protocol() (string, bool)
	// ResponseCode return the response code.
	ResponseCode() (uint32, bool)
	// ResponseCodeDetails return the response code details.
	ResponseCodeDetails() (string, bool)
	// AttemptCount return the number of times the request was attempted upstream.
	AttemptCount() uint32
	// Get the dynamic metadata of the request
	DynamicMetadata() DynamicMetadata
	// DownstreamLocalAddress return the downstream local address.
	DownstreamLocalAddress() string
	// DownstreamRemoteAddress return the downstream remote address.
	DownstreamRemoteAddress() string
	// UpstreamLocalAddress return the upstream local address.
	UpstreamLocalAddress() (string, bool)
	// UpstreamRemoteAddress return the upstream remote address.
	UpstreamRemoteAddress() (string, bool)
	// UpstreamClusterName return the upstream host cluster.
	UpstreamClusterName() (string, bool)
	// FilterState return the filter state interface.
	FilterState() FilterState
	// VirtualClusterName returns the name of the virtual cluster which got matched
	VirtualClusterName() (string, bool)
	// WorkerID returns the ID of the Envoy worker thread
	WorkerID() uint32

	// DownstreamRemoteParsedAddress returns the downstream remote address, in the IPAddress struct
	DownstreamRemoteParsedAddress() *IPAddress
}

Jump to

Keyboard shortcuts

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