Documentation
¶
Index ¶
- Constants
- func IsNetworkError(code int) bool
- type BodyFlushFunc
- type Context
- type FilterBuff
- type FinishFunc
- type HTTPContext
- type HTTPRequest
- type HTTPResponse
- type HTTPResult
- type HTTPTemplate
- type HandlerCaller
- type LazyTagFunc
- type MQTTClient
- type MQTTContext
- type MQTTPacketType
- type MQTTResult
- type MockMQTTClient
- type Protocol
- type TCPContext
- type TCPResult
- type UDPContext
- type UDPResult
Constants ¶
const ( EGStatusContinue = http.StatusContinue EGStatusSwitchingProtocols = http.StatusSwitchingProtocols EGStatusProcessing = http.StatusProcessing EGStatusOK = http.StatusOK EGStatusCreated = http.StatusCreated EGStatusAccepted = http.StatusAccepted EGStatusNoContent = http.StatusNoContent EGStatusPartialContent = http.StatusPartialContent EGStatusSpecialResponse = 300 // http.StatusMultipleChoices EGStatusMovedPermanently = http.StatusMovedPermanently EGStatusMovedTemporarily = 302 // http.StatusFound EGStatusSeeOther = http.StatusSeeOther EGStatusNotModified = http.StatusNotModified EGStatusTemporaryRedirect = http.StatusTemporaryRedirect EGStatusBadRequest = http.StatusBadRequest EGStatusForbidden = http.StatusForbidden EGStatusNotFound = http.StatusNotFound EGStatusNotAllowed = http.StatusMethodNotAllowed EGStatusRequestTimeOut = http.StatusRequestTimeout EGStatusConflict = http.StatusConflict EGStatusLengthRequired = http.StatusLengthRequired EGStatusPreconditionFailed = http.StatusPreconditionFailed EGStatusRequestEntityTooLarge = http.StatusRequestEntityTooLarge EGStatusRequestURITooLong = http.StatusRequestURITooLong EGStatusUnsupportedMediaType = http.StatusUnsupportedMediaType EGStatusRangeNotSatisfiable = http.StatusRequestedRangeNotSatisfiable EGStatusTooManyRequests = http.StatusTooManyRequests EGStatusClose = 444 EGStatusEgCodes = 494 EGStatusRequestHeaderTooLarge = 494 EGStatusHTTPSCertError = 495 EGStatusHTTPSNoCert = 496 EGStatusToHTTPS = 497 EGStatusClientClosedRequest = 499 EGStatusInternalServerError = http.StatusInternalServerError EGStatusNotImplemented = http.StatusNotImplemented EGStatusBadGateway = http.StatusBadGateway EGStatusGatewayTimeOut = http.StatusGatewayTimeout EGStatusInsufficientStorage = http.StatusInsufficientStorage EGStatusBadResponse = 599 )
the error code list which align with the HTTP status code
Variables ¶
This section is empty.
Functions ¶
func IsNetworkError ¶
IsNetworkError returns if the error is network type.
Types ¶
type BodyFlushFunc ¶
BodyFlushFunc is the type of function to be called back when body is flushing.
type Context ¶ added in v1.4.1
type Context interface {
stdcontext.Context
Protocol() Protocol
}
Context is general context for HTTPContext, MQTTContext, TCPContext
type FilterBuff ¶
FilterBuff stores filter's name and its YAML bytes
type FinishFunc ¶
type FinishFunc = func()
FinishFunc is the type of function to be called back when HTTPContext is finishing.
type HTTPContext ¶
type HTTPContext interface {
Context
Lock()
Unlock()
Request() HTTPRequest
Response() HTTPResponse
Cancel(err error)
Cancelled() bool
ClientDisconnected() bool
OnFinish(FinishFunc) // For setting final client statistics, etc.
AddTag(tag string) // For debug, log, etc.
AddLazyTag(LazyTagFunc) // Return LazyTags as strings.
StatMetric() *httpstat.Metric
Finish()
Template() texttemplate.TemplateEngine
SetTemplate(ht *HTTPTemplate)
SaveReqToTemplate(filterName string) error
SaveRspToTemplate(filterName string) error
CallNextHandler(lastResult string) string
SetHandlerCaller(caller HandlerCaller)
Tracing() *tracing.Tracing
}
HTTPContext is all context of an HTTP processing. It is not goroutine-safe, callers must use Lock/Unlock to protect it by themselves.
func New ¶
func New(stdw http.ResponseWriter, stdr *http.Request, tracingInstance *tracing.Tracing, spanName string) HTTPContext
New creates an HTTPContext. NOTE: We can't use sync.Pool to recycle context. Reference: https://github.com/gin-gonic/gin/issues/1731
func NewEmptyContext ¶ added in v1.4.1
func NewEmptyContext() HTTPContext
NewEmptyContext for testing.
type HTTPRequest ¶
type HTTPRequest interface {
RealIP() string
Method() string
SetMethod(method string)
// URL
Scheme() string
Host() string
SetHost(host string)
Path() string
SetPath(path string)
EscapedPath() string
Query() string
SetQuery(query string)
Fragment() string
Proto() string
Header() *httpheader.HTTPHeader
Cookie(name string) (*http.Cookie, error)
Cookies() []*http.Cookie
AddCookie(cookie *http.Cookie)
Body() io.Reader
SetBody(io.Reader, bool)
Std() *http.Request
Size() uint64 // bytes
}
HTTPRequest is all operations for HTTP request.
type HTTPResponse ¶ added in v1.1.0
type HTTPResponse interface {
StatusCode() int // Default is 200
SetStatusCode(code int)
Header() *httpheader.HTTPHeader
SetCookie(cookie *http.Cookie)
SetBody(body io.Reader)
Body() io.Reader
OnFlushBody(BodyFlushFunc)
Std() http.ResponseWriter
Size() uint64 // bytes
}
HTTPResponse is all operations for HTTP response.
type HTTPResult ¶ added in v1.4.1
type HTTPResult struct {
Err error
}
HTTPResult is result for handling http request
type HTTPTemplate ¶
type HTTPTemplate struct {
Engine texttemplate.TemplateEngine
// contains filtered or unexported fields
}
HTTPTemplate is the wrapper of template engine for Easegress
func NewHTTPTemplate ¶
func NewHTTPTemplate(filterBuffs []FilterBuff) (*HTTPTemplate, error)
NewHTTPTemplate returns a default HTTPTemplate
func (*HTTPTemplate) Render ¶
func (e *HTTPTemplate) Render(input string) (string, error)
Render using engine to render template
func (*HTTPTemplate) SaveRequest ¶
func (e *HTTPTemplate) SaveRequest(filterName string, ctx HTTPContext) error
SaveRequest transforms HTTPRequest related fields into template engine's dictionary
func (*HTTPTemplate) SaveResponse ¶
func (e *HTTPTemplate) SaveResponse(filterName string, ctx HTTPContext) error
SaveResponse transforms HTTPResponse related fields into template engine's dictionary
type HandlerCaller ¶
HandlerCaller is a helper function to call the handler
type LazyTagFunc ¶ added in v1.4.1
type LazyTagFunc = func() string
LazyTagFunc is the type of function to be called back when converting lazy tags to strings.
type MQTTClient ¶ added in v1.4.1
type MQTTClient interface {
ClientID() string
UserName() string
Load(key interface{}) (value interface{}, ok bool)
Store(key interface{}, value interface{})
Delete(key interface{})
}
MQTTClient contains client info that send this packet
type MQTTContext ¶ added in v1.4.1
type MQTTContext interface {
Context
Client() MQTTClient
Cancel(error)
Canceled() bool
Duration() time.Duration
Finish()
PacketType() MQTTPacketType
ConnectPacket() *packets.ConnectPacket // read only
DisconnectPacket() *packets.DisconnectPacket // read only
SubscribePacket() *packets.SubscribePacket // read only
UnsubscribePacket() *packets.UnsubscribePacket // read only
PublishPacket() *packets.PublishPacket // read only
SetDrop() // set drop value to true
Drop() bool // if true, this mqtt packet will be dropped
SetDisconnect() // set disconnect value to true
Disconnect() bool // if true, this mqtt client will be disconnected
SetEarlyStop() // set early stop value to true
EarlyStop() bool // if early stop is true, pipeline will skip following filters and return
SetKV(string, interface{})
GetKV(string) interface{}
}
MQTTContext is context for MQTT protocol
func NewMQTTContext ¶ added in v1.4.1
func NewMQTTContext(ctx stdcontext.Context, client MQTTClient, packet packets.ControlPacket) MQTTContext
NewMQTTContext create new MQTTContext
type MQTTPacketType ¶ added in v1.4.1
type MQTTPacketType int
MQTTPacketType contains supported mqtt packet type
const ( // MQTTConnect is mqtt packet type of connect MQTTConnect MQTTPacketType = 1 // MQTTPublish is mqtt packet type of publish MQTTPublish MQTTPacketType = 2 // MQTTDisconnect is mqtt packet type of disconnect MQTTDisconnect MQTTPacketType = 3 // MQTTSubscribe is mqtt packet type of subscribe MQTTSubscribe MQTTPacketType = 4 // MQTTUnsubscribe is mqtt packet type of unsubscribe MQTTUnsubscribe MQTTPacketType = 5 // MQTTOther is all other mqtt packet type MQTTOther MQTTPacketType = 99 )
type MQTTResult ¶ added in v1.4.1
type MQTTResult struct {
ErrString string
}
MQTTResult is result for handling mqtt request
type MockMQTTClient ¶ added in v1.4.1
MockMQTTClient is mock client for MQTTContext
func (*MockMQTTClient) ClientID ¶ added in v1.4.1
func (m *MockMQTTClient) ClientID() string
ClientID return client id of MockMQTTClient
func (*MockMQTTClient) Delete ¶ added in v1.4.1
func (m *MockMQTTClient) Delete(key interface{})
Delete delete key-value pair in MockMQTTClient kv map
func (*MockMQTTClient) Load ¶ added in v1.4.1
func (m *MockMQTTClient) Load(key interface{}) (value interface{}, ok bool)
Load load value keep in MockMQTTClient kv map
func (*MockMQTTClient) Store ¶ added in v1.4.1
func (m *MockMQTTClient) Store(key interface{}, value interface{})
Store store kv pair into MockMQTTClient kv map
func (*MockMQTTClient) UserName ¶ added in v1.4.1
func (m *MockMQTTClient) UserName() string
UserName return username if MockMQTTClient
type Protocol ¶ added in v1.4.1
type Protocol string
Protocol is type of protocol that context support
type TCPContext ¶ added in v1.4.1
type TCPContext interface {
Context
}
TCPContext is context for TCP protocol
type TCPResult ¶ added in v1.4.1
type TCPResult struct {
Err error
}
TCPResult is result for handling TCP request
type UDPContext ¶ added in v1.4.1
type UDPContext interface {
Context
}
UDPContext is context for UDP protocol