Documentation
¶
Index ¶
- Constants
- func EmitBodySize(bodySize int, direction string, truncated bool)
- func RegisterConfig(mp *Processor)
- type BlockActionOptions
- type ContinueActionOptions
- type HTTPBody
- type InputMessage
- type MessageType
- type Processor
- func (mp *Processor) Close() error
- func (mp *Processor) OnRequestBody(req HTTPBody, reqState *RequestState) error
- func (mp *Processor) OnRequestHeaders(ctx context.Context, req RequestHeaders) (reqState RequestState, err error)
- func (mp *Processor) OnRequestTrailers(reqState *RequestState) error
- func (mp *Processor) OnResponseBody(resp HTTPBody, reqState *RequestState) error
- func (mp *Processor) OnResponseHeaders(res ResponseHeaders, reqState *RequestState) error
- func (mp *Processor) OnResponseTrailers(reqState *RequestState) error
- type ProcessorConfig
- type PseudoRequest
- type PseudoResponse
- type RequestHeaders
- type RequestState
- type ResponseHeaders
Constants ¶
const ( // DefaultBodyParsingSizeLimit is the default number of bytes parsed for body analysis. DefaultBodyParsingSizeLimit = 10 * 1 << 20 // 10MB )
Variables ¶
This section is empty.
Functions ¶
func EmitBodySize ¶
func RegisterConfig ¶
func RegisterConfig(mp *Processor)
Types ¶
type BlockActionOptions ¶
type BlockActionOptions struct {
// StatusCode is the HTTP status code to be used in the block response, default is 403
StatusCode int
// Headers are the HTTP headers to be included in the block response, MUST contain at least "Content-Type"
// if a Body is provided (default is empty)
Headers map[string][]string
// Body is the HTTP body to be included in the block response (default is empty)
Body []byte
}
BlockActionOptions contains options for the block action created through [ProcessorConfig.BlockMessageFunc].
type ContinueActionOptions ¶
type ContinueActionOptions struct {
// HeaderMutations are the HTTP header mutations to be applied to the message (default is empty)
HeaderMutations map[string][]string
// Body indicates whether the body should be requested from the proxy to the external processing service (default is false)
Body bool
// MessageType indicates when the response is being created
MessageType MessageType
}
ContinueActionOptions contains options for the continue action created through [ProcessorConfig.ContinueMessageFunc].
type HTTPBody ¶
type HTTPBody interface {
InputMessage
GetBody() []byte
}
HTTPBody is an interface for accessing the body of an HTTP message used by the message processor. Whenever request or response body. It can be only a fraction of the full body. and multiple of these messages can be sent.
type InputMessage ¶
type InputMessage interface {
GetEndOfStream() bool
MessageType() MessageType
}
type MessageType ¶
type MessageType int
MessageType defines the type of message being processed.
const ( MessageTypeRequestHeaders MessageType MessageTypeRequestBody MessageTypeRequestTrailers MessageTypeResponseHeaders MessageTypeResponseBody MessageTypeResponseTrailers MessageTypeBlocked MessageTypeFinished )
func (MessageType) Ongoing ¶
func (mt MessageType) Ongoing() bool
func (MessageType) Request ¶
func (mt MessageType) Request() bool
func (MessageType) Response ¶
func (mt MessageType) Response() bool
func (MessageType) String ¶
func (mt MessageType) String() string
type Processor ¶
type Processor struct {
ProcessorConfig
// contains filtered or unexported fields
}
Processor is a state machine that handles incoming HTTP request and response is a streaming manner made for proxy external processing streaming protocols like Envoy's External Processing or HAProxy's SPOP
func NewProcessor ¶
func NewProcessor(config ProcessorConfig, instr *instrumentation.Instrumentation) Processor
NewProcessor creates a new Processor instance with the given configuration and instrumentation It also initializes the metrics reporter and a context cancellation function
func (*Processor) OnRequestBody ¶
func (mp *Processor) OnRequestBody(req HTTPBody, reqState *RequestState) error
OnRequestBody handles incoming request body chunks using the HTTPBody interface It uses the provided RequestState to keep track of the request/response cycle state It returns an optional output message of type O created by either [ProcessorConfig.ContinueMessageFunc] or [ProcessorConfig.BlockMessageFunc] If the request is blocked or the message ends the stream, it returns io.EOF as error Once the whole body has been received, it will try to parse it following the Content-Type header and if the body is not too large, it will be analyzed by the WAF
func (*Processor) OnRequestHeaders ¶
func (mp *Processor) OnRequestHeaders(ctx context.Context, req RequestHeaders) (reqState RequestState, err error)
OnRequestHeaders handles incoming request headers using the RequestHeaders interface It returns a RequestState to be used in subsequent calls for the same request/response cycle along with an optional output message of type O created by either [ProcessorConfig.ContinueMessageFunc] or [ProcessorConfig.BlockMessageFunc] If the request is blocked or the message ends the stream, it returns io.EOF as error
func (*Processor) OnRequestTrailers ¶
func (mp *Processor) OnRequestTrailers(reqState *RequestState) error
OnRequestTrailers handles incoming request trailers
func (*Processor) OnResponseBody ¶
func (mp *Processor) OnResponseBody(resp HTTPBody, reqState *RequestState) error
OnResponseBody handles incoming response body chunks using the HTTPBody interface It uses the provided RequestState to keep track of the request/response cycle state It returns an optional output message of type O created by either [ProcessorConfig.ContinueMessageFunc] or [ProcessorConfig.BlockMessageFunc] If the request is blocked or the message ends the stream, it returns io.EOF as error Once the whole body has been received, it will try to parse it following the Content-Type header and if the body is not too large, it will be analyzed by the WAF
func (*Processor) OnResponseHeaders ¶
func (mp *Processor) OnResponseHeaders(res ResponseHeaders, reqState *RequestState) error
OnResponseHeaders handles incoming response headers using the ResponseHeaders interface It returns a RequestState to be used in subsequent calls for the same request/response cycle along with an optional output message of type O created by either [ProcessorConfig.ContinueMessageFunc] or [ProcessorConfig.BlockMessageFunc] If the request is blocked or the message ends the stream, it returns io.EOF as error
func (*Processor) OnResponseTrailers ¶
func (mp *Processor) OnResponseTrailers(reqState *RequestState) error
OnResponseTrailers handles incoming response trailers
type ProcessorConfig ¶
type ProcessorConfig struct {
context.Context
BodyParsingSizeLimit *int
Framework string
// ContinueMessageFunc is a function that generates a continue message of type O based on the provided ContinueActionOptions.
ContinueMessageFunc func(context.Context, ContinueActionOptions) error
// BlockMessageFunc is a function that generates a block message of type O based on the provided status code, headers, and body.
BlockMessageFunc func(context.Context, BlockActionOptions) error
}
ProcessorConfig contains configuration for the message processor
type PseudoRequest ¶
type PseudoRequest struct {
Scheme string
Authority string
Path string
Method string
RemoteAddr string
Headers map[string][]string
}
PseudoRequest represents the pseudo headers of an HTTP request.
type PseudoResponse ¶
PseudoResponse represents the pseudo headers of an HTTP response.
type RequestHeaders ¶
type RequestHeaders interface {
InputMessage
// ExtractRequest extracts the pseudo headers and other relevant information from the request.
ExtractRequest(context.Context) (PseudoRequest, error)
// SpanOptions returns additional options to use when starting the span for this request.
SpanOptions(context.Context) []tracer.StartSpanOption
// BodyParsingSizeLimit returns the default value for body processing based on the request.
BodyParsingSizeLimit(ctx context.Context) int
}
RequestHeaders is an interface for accessing request headers used by the message processor.
type RequestState ¶
type RequestState struct {
Context context.Context
// Processing state
State MessageType
// contains filtered or unexported fields
}
RequestState manages the state of a single request through its lifecycle
func (*RequestState) BlockAction ¶
func (rs *RequestState) BlockAction() BlockActionOptions
BlockAction marks the request as blocked and completes it.
func (*RequestState) Close ¶
func (rs *RequestState) Close() error
Close finalizes the request processing.
func (*RequestState) PropagationHeaders ¶
func (rs *RequestState) PropagationHeaders() (http.Header, error)
PropagationHeaders creates header mutations for trace propagation
type ResponseHeaders ¶
type ResponseHeaders interface {
InputMessage
// ExtractResponse extracts the response headers and other relevant information from the response.
ExtractResponse() (PseudoResponse, error)
}
ResponseHeaders is an interface for accessing response headers used by the message processor.