From eeb44e5b915d2d8284cd8b736ca88339801e90f9 Mon Sep 17 00:00:00 2001 From: sada-sigsci Date: Mon, 26 Jun 2023 18:22:40 -0700 Subject: [PATCH] Added config option to send request body of any content type to agent --- config.go | 10 ++++++++++ module.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/config.go b/config.go index 2cf82d4..b0edde1 100644 --- a/config.go +++ b/config.go @@ -47,6 +47,7 @@ type ModuleConfig struct { anomalyDuration time.Duration anomalySize int64 expectedContentTypes []string + extendContentTypes bool debug bool rawHeaderExtractor RawHeaderExtractorFunc inspector Inspector @@ -278,6 +279,15 @@ func ExpectedContentType(s string) ModuleConfigOption { } } +// ExtendContentTypes is a function argument to indicate that send request body +// of any content-type to the agent for inspection +func ExtendContentTypes(v bool) ModuleConfigOption { + return func(c *ModuleConfig) error { + c.extendContentTypes = v + return nil + } +} + // CustomInspector is a function argument that sets a custom inspector, // an optional inspector initializer to decide if inspection should occur, and // an optional inspector finalizer that can perform any post-inspection steps diff --git a/module.go b/module.go index e8b4457..88a04b4 100644 --- a/module.go +++ b/module.go @@ -385,6 +385,10 @@ func shouldReadBody(req *http.Request, m *Module) bool { return true } + if m.config.extendContentTypes { + return true + } + // read the body if there are multiple Content-Type headers if len(req.Header.Values("Content-Type")) > 1 { return true