Skip to content

Commit

Permalink
extra options
Browse files Browse the repository at this point in the history
  • Loading branch information
jptosso committed Feb 7, 2024
1 parent f2556e5 commit 7d69e57
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions experimental/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,44 @@ type Options struct {

// ProcessResponse enables the processing of the response
// If the response is not processed, the middleware will only consume
// request headers and request body. It will also just run phases 1 and 2.
// request headers and request body, also, response will have to be
// processed by the next handler.
// The next handler will only have access to the request body through
// the transaction object.
ProcessResponse bool

// AutoClose enables the automatic closing of the transaction
// If the transaction is closed, request and body buffers cannot
// be retrieved. Interruption will still be available under the
// request context
// Please note that if a Transaction is not properly closed,
// it will lead to a memory leak. Transactions can be closed manually:
// ctx.Value("coraza_transaction").(types.Transaction).Close()
AutoClose bool

// WAF represents the WAF instance to use
// New transactions will be created using this WAF instance
WAF coraza.WAF

// SamplingRate represents the rate of sampling for the middleware
// If the rate is 0, the middleware will not sample
// If the rate is 100, the middleware will sample all requests
SamplingRate int
}

// DefaultOptions returns the default options for the middleware
// Default options are:
// - EnforceBlocking: true
// - AutoClose: true
// - ProcessResponse: false
// - SamplingRate: 0%
func DefaultOptions(waf coraza.WAF) Options {
return Options{
EnforceBlocking: true,
AutoClose: true,
ProcessResponse: false,
WAF: waf,
SamplingRate: 0,
}
}

Expand All @@ -42,7 +66,8 @@ func DefaultOptions(waf coraza.WAF) Options {
// - coraza_interruption: types.Interruption
//
// The middleware will flush the request body and it will consume
// the response in case ProcessResponse Option is enabled
// the response in case ProcessResponse Option is enabled.
// Request and Response bodies can be accessed through the transaction object.
// Some additional Context variables are available to create transactions:
// - coraza_transaction_id: string
func WrapHandler(options Options, h http.Handler) http.Handler {
Expand Down

0 comments on commit 7d69e57

Please sign in to comment.