-
-
Notifications
You must be signed in to change notification settings - Fork 304
fix: streamed responses #1449
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
fix: streamed responses #1449
Conversation
Signed-off-by: daum3ns <[email protected]>
…racks whether the Flush() was invoked. like this we can really check whether the flush was correctly propagated. Signed-off-by: daum3ns <[email protected]>
…on basic functionality, add a test with a rule match in phase 3 Signed-off-by: daum3ns <[email protected]>
case responsebody is not accessable or processable
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1449 +/- ##
==========================================
+ Coverage 85.12% 85.27% +0.14%
==========================================
Files 173 173
Lines 8336 8400 +64
==========================================
+ Hits 7096 7163 +67
+ Misses 993 991 -2
+ Partials 247 246 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: daum3ns <[email protected]>
|
GREAT WORK! Any chance we get a test in e2e? https://github.com/corazawaf/coraza/blob/main/http/e2e/e2e.go |
|
are the e2e tests intended to be run manually? at least it looks like it expects something running on localhost 8080 and 8081? |
Signed-off-by: daum3ns <[email protected]>
jptosso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, looking to resolve @jcchavezs question
|
i think the current e2e setup doesn't allow to easily do that... |
TestCase types Signed-off-by: daum3ns <[email protected]>
Signed-off-by: daum3ns <[email protected]>
Signed-off-by: daum3ns <[email protected]>
|
I have added the basis for the e2e test, however at the moment there is no verification on client side that the response is streamed. in other words the test also succeeds if we put it in the Run() method, (which shouldn't because the body is buffered).. Also do you think its better to have an own set of directives, or should I integrate it in the existing directives using this Rule: |
streaming callback to testconfiguration Signed-off-by: daum3ns <[email protected]>
Signed-off-by: daum3ns <[email protected]>
Signed-off-by: daum3ns <[email protected]>
runnner". Signed-off-by: daum3ns <[email protected]>
Signed-off-by: daum3ns <[email protected]>
|
okay I think this should be fine for an e2e scenario.. I figured out that we can easily do it in the main Run because of the MimeType settings. Response body access is on, but the mime type is not defined (i.e. tx.IsProcessable == false) to be inspected so the body gets streamed correctly. I have additionally added such a setup in the streaming_test.go. however, when I was playing around with the directives, I fount out that removing the this happens in the main branch as well, so it's not introduced by this PR.. But I don't know, do you guys think that it is a problem? |
Signed-off-by: daum3ns <[email protected]>
Signed-off-by: daum3ns <[email protected]>
Signed-off-by: daum3ns <[email protected]>
|
Amazing work! I am inclined to merge it. Any thoughts @M4tteoP ? |
|
I took the freedom to cherry-pick some of the great improvements in here that are not tied to the streaming support into another PR so we can review this easier #1459 |
|
Testing the e2e in
@fionera wanna test it in coraza-spoa? |
|
Apparently it works as expected in envoy https://github.com/corazawaf/coraza-proxy-wasm/actions/runs/20431263460/job/58705278664?pr=312#step:9:438 |
|
It failed as expected in caddy :) https://github.com/corazawaf/coraza-caddy/actions/runs/20432299095/job/58705536937?pr=253#step:7:206 |
|
Looks like it works, thanks! but I'd like a second review from @M4tteoP |
| if totalDeadline <= 0 { | ||
| totalDeadline = 30 * time.Second | ||
| } | ||
| if firstChunkDeadline < 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in which case would this be <0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes issue #1120 by enabling HTTP response streaming when SecResponseBodyAccess is off or when response body is not processable. The fix prevents Coraza from buffering responses that don't need body inspection, allowing frameworks like Next.js to properly stream content to clients.
Key Changes
- Added
allowFlushingflag to the response writer interceptor that enables flush propagation when response body inspection is disabled - Implemented comprehensive streaming tests covering multiple scenarios (engine off, MIME type mismatch, response body access off, header blocking, HTTP/1.0)
- Extended E2E test framework with SSE streaming verification capabilities
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| http/interceptor.go | Added allowFlushing flag that is set when response body isn't accessible/processable; modified Flush() to propagate flush calls when flag is true |
| http/streaming_test.go | New comprehensive test file with 5 test cases validating streaming behavior across different WAF configurations and scenarios |
| http/e2e/e2e.go | Added StreamCheck type and VerifySSEStreamResponse function for validating progressive SSE streaming; refactored body length checking to use actual body length instead of Content-Length header; added SSE test case |
| http/e2e/e2e_test.go | Added unit tests for new SSE verification functions and other e2e helper functions; updated status code expectations to use http constants |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
M4tteoP
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pull request fixes #1120 by preventing Coraza from buffering responses when
SecResponseBodyAccess offis enabled.allowFlushingin the interceptor.goThanks for your contribution ❤️