Documentation
¶
Index ¶
- Constants
- func BodyProcessConfigCheck(config *BodyProcessConfig) error
- func GetAuditData(ev Event) ([]byte, error)
- func GetEventTokens(ev Event) int64
- func GetHTTPClient() *http.Client
- func ProductRuleConfLoad(filename string) (productRuleConf, error)
- func SetAuditData(ev Event, data []byte) error
- func SetHTTPClient(client *http.Client)
- type BPError
- type BodyProcessConfig
- type BodyProcessor
- func (bp *BodyProcessor) AddProcessor(p EventProcessor)
- func (bp *BodyProcessor) Close() error
- func (bp *BodyProcessor) CreateEventDecoder(fac EventDecoderFac)
- func (bp *BodyProcessor) CreateEventEncoder(fac EventEncoderFac)
- func (bp *BodyProcessor) FillBuffer() error
- func (bp *BodyProcessor) GetSource() io.ReadCloser
- func (bp *BodyProcessor) OnReject(fn func(error, *BodyProcessor))
- func (bp *BodyProcessor) Read(p []byte) (n int, err error)
- func (bp *BodyProcessor) RejectionResponse() *RejectionError
- type ConfModBodyProcess
- type ContentAudit
- type ContentTypeDecoder
- type Event
- type EventDecoder
- type EventDecoderFac
- type EventDecoderFacWithReq
- type EventEncoder
- type EventEncoderFac
- type EventProcessor
- type EventProcessorFunc
- type GeneralEncoder
- type JsonDecoder
- type LineDecoder
- type ModuleBodyProcess
- func (m *ModuleBodyProcess) DoRequestProcess(req *bfe_basic.Request, conf *BodyProcessConfig) *BodyProcessor
- func (m *ModuleBodyProcess) DoResponseProcess(req *bfe_basic.Request, res *bfe_http.Response, conf *BodyProcessConfig) *BodyProcessor
- func (m *ModuleBodyProcess) Init(cbs *bfe_module.BfeCallbacks, whs *web_monitor.WebHandlers, cr string) error
- func (m *ModuleBodyProcess) Name() string
- type ModuleBodyProcessState
- type ProcConf
- type ProcessRuleTable
- type ProductRules
- type ProductRulesFile
- type RawEvent
- type RejectionError
- type SSEEvent
- type SSEEventDecoder
- type TextFilterContactItem
- type TextFilterDetailItem
- type TextFilterResult
Constants ¶
View Source
const ( ModBodyProcess = "mod_body_process" BodyProcessResponseConfigKey = "mod_body_process.response_config" )
Variables ¶
This section is empty.
Functions ¶
func BodyProcessConfigCheck ¶
func BodyProcessConfigCheck(config *BodyProcessConfig) error
func GetAuditData ¶
func GetEventTokens ¶
func GetHTTPClient ¶
func ProductRuleConfLoad ¶
func SetAuditData ¶
func SetHTTPClient ¶
Types ¶
type BodyProcessConfig ¶
type BodyProcessor ¶
type BodyProcessor struct {
// contains filtered or unexported fields
}
BodyProcessor 扩展中断支持
func NewBodyProcessor ¶
func NewBodyProcessor(source io.ReadCloser) *BodyProcessor
NewBodyProcessor 创建处理器
func (*BodyProcessor) AddProcessor ¶
func (bp *BodyProcessor) AddProcessor(p EventProcessor)
func (*BodyProcessor) CreateEventDecoder ¶
func (bp *BodyProcessor) CreateEventDecoder(fac EventDecoderFac)
func (*BodyProcessor) CreateEventEncoder ¶
func (bp *BodyProcessor) CreateEventEncoder(fac EventEncoderFac)
func (*BodyProcessor) FillBuffer ¶
func (bp *BodyProcessor) FillBuffer() error
FillBuffer 公开的缓冲区填充方法 安全地从源读取并处理一个数据块
func (*BodyProcessor) GetSource ¶
func (bp *BodyProcessor) GetSource() io.ReadCloser
func (*BodyProcessor) OnReject ¶
func (bp *BodyProcessor) OnReject(fn func(error, *BodyProcessor))
注册中断回调
func (*BodyProcessor) Read ¶
func (bp *BodyProcessor) Read(p []byte) (n int, err error)
Read 实现io.Reader接口(支持中断)
func (*BodyProcessor) RejectionResponse ¶
func (bp *BodyProcessor) RejectionResponse() *RejectionError
RejectionResponse 获取中断响应(如在反向代理中使用)
type ConfModBodyProcess ¶
type ConfModBodyProcess struct {
Basic struct {
ProductRulePath string
}
Log struct {
OpenDebug bool
}
}
func (*ConfModBodyProcess) Check ¶
func (cfg *ConfModBodyProcess) Check(confRoot string) error
type ContentAudit ¶
type ContentAudit struct {
// contains filtered or unexported fields
}
func NewContentAudit ¶
func NewContentAudit(urlStr string, replace bool) (*ContentAudit, error)
type ContentTypeDecoder ¶
type ContentTypeDecoder struct {
// contains filtered or unexported fields
}
func (*ContentTypeDecoder) Decode ¶
func (ctd *ContentTypeDecoder) Decode() ([]Event, error)
type Event ¶
type Event interface {
// GetType() string
// GetData() []byte
ToBytes() []byte // 转换为字节数组
}
type EventDecoder ¶
type EventDecoder interface {
// return:
// events, nil - len(events) > 0, success
// events, nil - len(events) = 0, 没有更多数据, eof
// nil, error - 发生错误
Decode() ([]Event, error)
}
func NewContentTypeDecoder ¶
func NewContentTypeDecoder(source io.Reader, contentType string) (EventDecoder, error)
func NewJsonDecoder ¶
func NewJsonDecoder(source io.Reader) (EventDecoder, error)
func NewLineDecoder ¶
func NewLineDecoder(source io.Reader) (EventDecoder, error)
func NewSSEEventDecoder ¶
func NewSSEEventDecoder(source io.Reader) (EventDecoder, error)
type EventDecoderFac ¶
type EventDecoderFac func(source io.Reader) (EventDecoder, error)
type EventDecoderFacWithReq ¶
type EventEncoder ¶
func NewGeneralEncoder ¶
func NewGeneralEncoder(dest io.Writer) (EventEncoder, error)
type EventEncoderFac ¶
type EventEncoderFac func(dest io.Writer) (EventEncoder, error)
type EventProcessor ¶
type EventProcessorFunc ¶
ProcessorFunc 简化处理器实现
func NewCalcCompletionQuota ¶
func NewCalcCompletionQuota(req *bfe_basic.Request) EventProcessorFunc
type GeneralEncoder ¶
type GeneralEncoder struct {
// contains filtered or unexported fields
}
type JsonDecoder ¶
type JsonDecoder struct {
// contains filtered or unexported fields
}
func (*JsonDecoder) Decode ¶
func (dec *JsonDecoder) Decode() ([]Event, error)
type LineDecoder ¶
type LineDecoder struct {
// contains filtered or unexported fields
}
func (*LineDecoder) Decode ¶
func (dec *LineDecoder) Decode() ([]Event, error)
type ModuleBodyProcess ¶
type ModuleBodyProcess struct {
// contains filtered or unexported fields
}
func NewModuleBodyProcess ¶
func NewModuleBodyProcess() *ModuleBodyProcess
func (*ModuleBodyProcess) DoRequestProcess ¶
func (m *ModuleBodyProcess) DoRequestProcess(req *bfe_basic.Request, conf *BodyProcessConfig) *BodyProcessor
func (*ModuleBodyProcess) DoResponseProcess ¶
func (m *ModuleBodyProcess) DoResponseProcess(req *bfe_basic.Request, res *bfe_http.Response, conf *BodyProcessConfig) *BodyProcessor
func (*ModuleBodyProcess) Init ¶
func (m *ModuleBodyProcess) Init(cbs *bfe_module.BfeCallbacks, whs *web_monitor.WebHandlers, cr string) error
func (*ModuleBodyProcess) Name ¶
func (m *ModuleBodyProcess) Name() string
type ModuleBodyProcessState ¶
type ProcessRuleTable ¶
type ProcessRuleTable struct {
// contains filtered or unexported fields
}
func NewTokenRuleTable ¶
func NewTokenRuleTable() *ProcessRuleTable
func (*ProcessRuleTable) Search ¶
func (t *ProcessRuleTable) Search(product string) (processRuleList, bool)
func (*ProcessRuleTable) Update ¶
func (t *ProcessRuleTable) Update(conf productRuleConf)
type ProductRules ¶
type ProductRules map[string]processRuleList
type ProductRulesFile ¶
type ProductRulesFile map[string]processRuleFileList
type RejectionError ¶
RejectionError 自定义错误类型
func (*RejectionError) Error ¶
func (e *RejectionError) Error() string
type SSEEvent ¶
type SSEEvent struct {
ID string
Event string
Data []byte
Retry int
// contains filtered or unexported fields
}
func (m *ModuleBodyProcess) DoResponseProcess(req *bfe_basic.Request, res *bfe_http.Response, conf *BodyProcessConfig) *BodyProcessor {
if conf == nil {
return nil // 没有配置,直接返回
}
m.state.ResProcess.Inc(1)
bp := NewBodyProcessor(res.Body)
switch conf.Dec {
case "sse": // sse is not available for request body
bp.CreateEventDecoder(NewSSEEventDecoder)
case "line":
bp.CreateEventDecoder(NewLineDecoder)
case "json":
bp.CreateEventDecoder(NewJsonDecoder)
default:
contentType := res.Header.Get("Content-Type")
bp.CreateEventDecoder(func(source io.Reader)(EventDecoder, error) {
return NewContentTypeDecoder(source, contentType)} ) // 使用ContentTypeDecoder根据Content-Type自动选择解码器
// bp.CreateEventDecoder(NewJsonDecoder) // 默认使用ndJson解码
}
bp.CreateEventEncoder(NewGeneralEncoder)
// 缺省添加streamcompletion处理器
p := NewCalcCompletionQuota(req)
if p != nil {
bp.AddProcessor(p)
}
for _, proc := range conf.Proc {
switch proc.Name {
case "textfilter":
caf, _ := NewContentAudit(proc.Params[0], true)
bp.AddProcessor(caf)
}
}
res.Body = bp
res.ContentLength = -1 // 设置为-1表示不确定长度
res.Header.Del("Content-Length")
return bp
}
SSEEvent 表示一个SSE事件
type SSEEventDecoder ¶
type SSEEventDecoder struct {
// contains filtered or unexported fields
}
func (*SSEEventDecoder) Decode ¶
func (dec *SSEEventDecoder) Decode() ([]Event, error)
type TextFilterContactItem ¶
type TextFilterDetailItem ¶
type TextFilterResult ¶
type TextFilterResult struct {
Code int32
Message string
RequestId string
RiskLevel string
RiskCode string
SentimentScore float32
ResultText string
Details []TextFilterDetailItem
Contacts []TextFilterContactItem
}
Click to show internal directories.
Click to hide internal directories.