github.com/crowdsecurity/crowdsec@v1.6.1/pkg/acquisition/modules/appsec/bodyprocessors/raw.go (about) 1 package bodyprocessors 2 3 import ( 4 "io" 5 "strconv" 6 "strings" 7 8 "github.com/crowdsecurity/coraza/v3/experimental/plugins" 9 "github.com/crowdsecurity/coraza/v3/experimental/plugins/plugintypes" 10 ) 11 12 type rawBodyProcessor struct { 13 } 14 15 type setterInterface interface { 16 Set(string) 17 } 18 19 func (*rawBodyProcessor) ProcessRequest(reader io.Reader, v plugintypes.TransactionVariables, options plugintypes.BodyProcessorOptions) error { 20 buf := new(strings.Builder) 21 if _, err := io.Copy(buf, reader); err != nil { 22 return err 23 } 24 25 b := buf.String() 26 27 v.RequestBody().(setterInterface).Set(b) 28 v.RequestBodyLength().(setterInterface).Set(strconv.Itoa(len(b))) 29 return nil 30 } 31 32 func (*rawBodyProcessor) ProcessResponse(reader io.Reader, v plugintypes.TransactionVariables, options plugintypes.BodyProcessorOptions) error { 33 return nil 34 } 35 36 var ( 37 _ plugintypes.BodyProcessor = &rawBodyProcessor{} 38 ) 39 40 //nolint:gochecknoinits //Coraza recommends to use init() for registering plugins 41 func init() { 42 plugins.RegisterBodyProcessor("raw", func() plugintypes.BodyProcessor { 43 return &rawBodyProcessor{} 44 }) 45 }