Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental: UseRequest/ResponseBody methods #1212

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

M4tteoP
Copy link
Member

@M4tteoP M4tteoP commented Nov 12, 2024

Exposing as experimental two new methods to provide the bodies to Coraza. They are meant to be used when the entire request body is available, as it avoids the need for an extra copy into the body buffers.

Benchmark:

goos: darwin
goarch: arm64
pkg: github.com/corazawaf/coraza/v3/internal/corazawaf
BenchmarkUseRequestBody/WriteRequestBody-10         	    1383	    912582 ns/op	10544513 B/op	     214 allocs/op
BenchmarkUseRequestBody/UseRequestBody-10           	   63420	     17178 ns/op	   50075 B/op	     212 allocs/op
PASS
ok  	github.com/corazawaf/coraza/v3/internal/corazawaf	3.559s

Usage:

tx := waf.NewTransaction().(corazaexperimental.Transaction)
body := []byte("body") // Retrieved from the connector or somewhere
tx.UseResponseBody(body)

Usage:

@M4tteoP M4tteoP marked this pull request as ready for review November 13, 2024 00:12
@M4tteoP M4tteoP requested a review from a team as a code owner November 13, 2024 00:12
@jptosso
Copy link
Member

jptosso commented Nov 13, 2024

My only concern is maintaining a pointer that can be flushed at any point.
I'm not sure if telling the user to avoid using b slice is enough

@M4tteoP
Copy link
Member Author

M4tteoP commented Nov 13, 2024

My only concern is maintaining a pointer that can be flushed at any point.
I'm not sure if telling the user to avoid using b slice is enough

Hey, I elaborated on the description a bit more. However, this feature fundamentally relies on this approach, so I would assume that anyone using it is intentionally willing to let Coraza the ownership of that pointer

@jcchavezs
Copy link
Member

jcchavezs commented Nov 14, 2024

I am missing the use cases where this can be used. In regular go code I think it is risky as mutations can happen, in other environments I think is more acceptable. I would not merge this until we show solid code using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants