Fix potential panic in audit during header formatting (#22694)

This commit is contained in:
Peter Wilson
2023-08-31 18:44:35 +01:00
committed by GitHub
parent 56ce89544e
commit d2d3d8a27d
3 changed files with 58 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ package audit
import (
"errors"
"reflect"
"strings"
"time"
)
@@ -150,9 +151,13 @@ func WithHMACAccessor(h bool) Option {
}
// WithHeaderFormatter provides an Option to supply a HeaderFormatter.
// If the HeaderFormatter interface supplied is nil (type or value), the option will not be applied.
func WithHeaderFormatter(f HeaderFormatter) Option {
return func(o *options) error {
o.withHeaderFormatter = f
if f != nil && !reflect.ValueOf(f).IsNil() {
o.withHeaderFormatter = f
}
return nil
}
}