protocol

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 10 Imported by: 32

Documentation

Index

Constants

View Source
const (
	Auto  api.ProtocolName = "Auto"
	HTTP1 api.ProtocolName = "Http1" // TODO: move it to protocol/HTTP
	HTTP2 api.ProtocolName = "Http2" // TODO: move it to protocol/HTTP2

)

ProtocolName type definition

View Source
const (
	Request  = "Request"
	Response = "Response"
)

header direction definition

Variables

View Source
var (
	ErrNoMapping         = errors.New("no mapping function found")
	ErrInvalidParameters = errors.New("new connection pool or protocol stream factory cannot be nil")
	ErrDuplicateProtocol = errors.New("duplicated protocol registered")
)

The api for get the registered info

View Source
var (
	FAILED = errors.New("FAILED")
	EAGAIN = errors.New("AGAIN")
)
View Source
var ErrNoStatusCode = errors.New("headers have no status code")

Functions

func GenerateID

func GenerateID() uint64

GenerateID get id by default global generator

func GenerateIDString

func GenerateIDString() string

GenerateIDString get id string by default global generator

func GetNewPoolFactory added in v0.26.0

func GetNewPoolFactory(protocol api.ProtocolName) (types.NewConnPool, bool)

func GetProtocolStreamFactory added in v0.26.0

func GetProtocolStreamFactory(name api.ProtocolName) (types.ProtocolStreamFactory, bool)

func HandleConfig added in v0.23.0

func HandleConfig(prot api.ProtocolName, v interface{}) interface{}

func MappingHeaderStatusCode

func MappingHeaderStatusCode(ctx context.Context, p api.ProtocolName, headers api.HeaderMap) (int, error)

func ProtocolRegistered added in v0.26.0

func ProtocolRegistered(name api.ProtocolName) bool

func RangeAllRegisteredProtocol added in v0.26.0

func RangeAllRegisteredProtocol(f func(name api.ProtocolName))

func RegisterProtocol added in v0.26.0

func RegisterProtocol(name api.ProtocolName, newPool types.NewConnPool, streamFactory types.ProtocolStreamFactory, mapping api.HTTPMapping) error

A MOSN Protocol contains three parts: 1. A Factory to create connection pool defined by types.ConnectionPool 2. An interface to match protocol and create protocol stream for each request. 3. A status code mapping handler to translate protocol status code to HTTP status code, which is used as standard status code in MOSN.

func RegisterProtocolConfigHandler added in v0.23.0

func RegisterProtocolConfigHandler(prot api.ProtocolName, h ProtocolConfigHandler)

func RequestIDConv

func RequestIDConv(streamID string) uint64

RequestIDConv convert streamID from string to uint64

func SelectStreamFactoryProtocol added in v0.26.0

func SelectStreamFactoryProtocol(ctx context.Context, prot string, peek []byte, scopes []api.ProtocolName) (api.ProtocolName, error)

SelectStreamFactoryProtocol match the protocol. if scopes is nil, match all the registered protocols if scopes is not nil, match the protocol in the scopes

func StreamIDConv

func StreamIDConv(streamID uint64) string

StreamIDConv convert streamID from uint64 to string

Types

type CommonHeader

type CommonHeader map[string]string

TODO: use pkg.CommonHeader, why not? CommonHeader wrapper for map[string]string

func (CommonHeader) Add

func (h CommonHeader) Add(key string, value string)

Add value for given key. Multiple headers with the same key may be added with this function. Use Set for setting a single header for the given key.

func (CommonHeader) ByteSize

func (h CommonHeader) ByteSize() uint64

func (CommonHeader) Clone

func (h CommonHeader) Clone() api.HeaderMap

Clone used to deep copy header's map

func (CommonHeader) Del

func (h CommonHeader) Del(key string)

Del delete pair of specified key

func (CommonHeader) Get

func (h CommonHeader) Get(key string) (value string, ok bool)

Get value of key

func (CommonHeader) Range

func (h CommonHeader) Range(f func(key, value string) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (CommonHeader) Set

func (h CommonHeader) Set(key string, value string)

Set key-value pair in header map, the previous pair will be replaced if exists

type GetStatusCodeMapping added in v0.26.0

type GetStatusCodeMapping struct{}

GetStatusCodeMapping is a default http mapping implementation, which get status code from variable without any translation.

func (GetStatusCodeMapping) MappingHeaderStatusCode added in v0.26.0

func (m GetStatusCodeMapping) MappingHeaderStatusCode(ctx context.Context, headers api.HeaderMap) (int, error)

type IDGenerator

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

IDGenerator utility to generate auto-increment ids

func (*IDGenerator) Get

func (g *IDGenerator) Get() uint64

Get get id

func (*IDGenerator) GetString

func (g *IDGenerator) GetString() string

Get get id in string format

type ProtocolConfigHandler added in v0.23.0

type ProtocolConfigHandler func(v interface{}) interface{}

ProtocolConfigHandler translate general config into protocol configs

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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