func (m *Middleware) Validate() error {
	return nil
}
Validate implements caddy.Validator.
package filter
import (
	"bytes"
	"fmt"
	"io"
	"log"
	"net/http"
	"net/http/httptest"
	"regexp"
	"strconv"
	"go.uber.org/zap"
	"github.com/caddyserver/caddy/v2"
	"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
	"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
	"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
func init() {
	caddy.RegisterModule(Middleware{})
	httpcaddyfile.RegisterHandlerDirective("filter", parseCaddyfile)
}
var paramReplacementPattern = regexp.MustCompile("\\{[a-zA-Z0-9_\\-.]+?}")
type Middleware struct {
	ContentType string `json:"content_type"`
	SearchPattern string `json:"search_pattern"`
	Replacement []byte `json:"replacement"`
	MaxSize int    `json:"max_size"`
	Path    string `json:"path"`
	compiledContentTypeRegex *regexp.Regexp
	compiledSearchRegex      *regexp.Regexp
	compiledPathRegex        *regexp.Regexp
	logger *zap.Logger
}
func (Middleware) CaddyModule() caddy.ModuleInfo {
	return caddy.ModuleInfo{
		ID:  "http.handlers.filter",
		New: func() caddy.Module { return new(Middleware) },
	}
}
const DefaultMaxSize = 2 * 1024 * 1024
func (m *Middleware) Provision(ctx caddy.Context) error {
	var err error
	m.logger = ctx.Logger(m)
	m.logger.Debug(fmt.Sprintf("ContentType: %s. SearchPattern: %s",
		m.ContentType,
		m.SearchPattern))
	if m.MaxSize == 0 {
		m.MaxSize = DefaultMaxSize
	}
	if m.Path == "" {
		m.Path = ".*"
	}
	if m.compiledContentTypeRegex, err = regexp.Compile(m.ContentType); err != nil {
		return fmt.Errorf("invalid content_type: %w", err)
	}
	if m.compiledSearchRegex, err = regexp.Compile(m.SearchPattern); err != nil {
		return fmt.Errorf("invalid search_pattern: %w", err)
	}
	if m.compiledPathRegex, err = regexp.Compile(m.Path); err != nil {
		return fmt.Errorf("invalid path: %w", err)
	}
	return nil
}