Skip to content

Commit

Permalink
chore: expose request timestamp
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <[email protected]>
  • Loading branch information
fzipi committed Oct 21, 2024
1 parent 907db37 commit c5f74a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/corazawaf/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions internal/corazawaf/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c5f74a1

Please sign in to comment.