context

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
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
	EGStatusUnauthorized          = http.StatusUnauthorized
	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
	EGStatusServiceUnavailable    = http.StatusServiceUnavailable
	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

func IsNetworkError(code int) bool

IsNetworkError returns if the error is network type.

Types

type BodyFlushFunc

type BodyFlushFunc = func(body []byte, complete bool) (newBody []byte)

BodyFlushFunc is the type of function to be called back when body is flushing.

type FilterBuff

type FilterBuff struct {
	Name string
	Buff []byte
}

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 {
	Lock()
	Unlock()

	Span() tracing.Span

	Request() HTTPRequest
	Response() HTTPResponse

	stdcontext.Context
	Cancel(err error)
	Cancelled() bool
	ClientDisconnected() bool

	OnFinish(func())   // For setting final client statistics, etc.
	AddTag(tag string) // For debug, log, etc.

	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)
}

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,
	tracer *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

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)

	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(func(body []byte, complete bool) (newBody []byte))

	Std() http.ResponseWriter

	Size() uint64 // bytes
}

HTTPResponse is all operations for HTTP response.

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

type HandlerCaller func(lastResult string) string

HandlerCaller is a helper function to call the handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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