diff --git a/internal/corazawaf/transaction.go b/internal/corazawaf/transaction.go index c05128271..9daa7acef 100644 --- a/internal/corazawaf/transaction.go +++ b/internal/corazawaf/transaction.go @@ -1504,6 +1504,11 @@ func (tx *Transaction) AuditLog() *auditlog.Log { return al } +// UnixTimestamp returns the timestamp when the request was received. +func (tx *Transaction) UnixTimestamp() int64 { + return tx.Timestamp +} + // Close closes the transaction after phase 5 // This method helps the GC to clean up the transaction faster and release resources // It also allows caches the transaction back into the sync.Pool diff --git a/internal/corazawaf/transaction_test.go b/internal/corazawaf/transaction_test.go index bfff8821a..6006c171a 100644 --- a/internal/corazawaf/transaction_test.go +++ b/internal/corazawaf/transaction_test.go @@ -1716,6 +1716,15 @@ func TestForceRequestBodyOverride(t *testing.T) { } } +func TestGetUnixTimestamp(t *testing.T) { + tx := makeTransaction(t) + stamp := tx.UnixTimestamp() + t.Logf("stamp: %d", stamp) + if stamp <= 0 { + t.Fatalf("no timestamp found") + } +} + func TestCloseFails(t *testing.T) { waf := NewWAF() tx := waf.NewTransaction() diff --git a/types/transaction.go b/types/transaction.go index dfbb3c66e..a031a9e68 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -193,6 +193,8 @@ type Transaction interface { // ID returns the transaction ID. ID() string + // UnixTimestamp returns the transaction timestamp + UnixTimestamp() int64 // Closer closes the transaction and releases any resources associated with it such as request/response bodies. io.Closer }