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

fix http.Flusher and io.ReaderFrom implementation #923

Conversation

romainmenke
Copy link
Contributor

@romainmenke romainmenke commented Nov 20, 2023

Thank you for contributing to Coraza WAF, your effort is greatly appreciated
Before submitting check if what you want to add to coraza list meets quality standards before sending pull request. Thanks!

Make sure that you've checked the boxes below before you submit PR:


Before this change http.Flusher and io.ReaderFrom essentially acted like a bypass for the coraza middleware because they directly called the underlying writer.

http.Flusher is unimplementable because it doesn't make sense to flush early to the client. It does have one observable effect. A call to Flush before a call to Write (or WriteHeader) also implies a call to WriteHeader.

io.ReaderFrom can be implemented by linking it with Write through io.Copy

@romainmenke romainmenke requested a review from a team as a code owner November 20, 2023 15:56
Copy link

codecov bot commented Nov 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (48cf923) 81.81% compared to head (ff07fa4) 82.57%.

❗ Current head ff07fa4 differs from pull request most recent head fd8a173. Consider uploading reports for the commit fd8a173 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #923      +/-   ##
==========================================
+ Coverage   81.81%   82.57%   +0.75%     
==========================================
  Files         160      160              
  Lines        9064     8988      -76     
==========================================
+ Hits         7416     7422       +6     
+ Misses       1399     1317      -82     
  Partials      249      249              
Flag Coverage Δ
default 77.64% <100.00%> (+0.72%) ⬆️
examples 26.56% <15.38%> (+0.18%) ⬆️
ftw 47.01% <15.38%> (+0.37%) ⬆️
ftw-multiphase 49.21% <15.38%> (+0.39%) ⬆️
tinygo 75.14% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}

func (i *rwInterceptor) Flush() {
// coraza middleware always needs to buffer the entire request, response cycle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment made me take a closer look at http.Flusher and there is one thing that can and should be in this implementation.

WriteHeader must be called if it wasn't called before with a status code of 200.

Thank you for pointing out that the was room for improvement here.

http/interceptor_test.go Outdated Show resolved Hide resolved
@jcchavezs
Copy link
Member

It looks good to me, just fix the coverage. Any thoughts @anuraaga ?

@romainmenke
Copy link
Contributor Author

I am done with edits now.
I think this is ready for a second look.

Thank you @jcchavezs for the review 🙇

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@anuraaga anuraaga merged commit a95ea5f into corazawaf:main Nov 21, 2023
8 checks passed
@jcchavezs
Copy link
Member

jcchavezs commented Nov 21, 2023 via email

@romainmenke romainmenke deleted the fix-flush-and-readerfrom-implementation--generous-starfish-f8e6e94207 branch November 21, 2023 08:30
@romainmenke
Copy link
Contributor Author

Thank you for the reviews everyone 🙇

@jcchavezs
Copy link
Member

@mholt do you think this is something we should port to the caddy connector?

@mholt
Copy link

mholt commented Nov 27, 2023

That might be a good idea if it fixes a bug.

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.

4 participants