-
Notifications
You must be signed in to change notification settings - Fork 14
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
#921 Allow reading body multiple times #923
Conversation
Some of the methods cannot be implemented, so they are not operational.
Refactor the FnBodyBinder by creating private methods for specific binder tasks.
…as a bean instead of a string
It seems like with this fix: micronaut-projects/micronaut-servlet#740 we can have an implementation using InputStreamByteBody. Not sure if this is better now. |
8701a10
to
ab4601e
Compare
@andriy-dmytruk PTAL. My byteBody approach is detailed in this comment: fd99aaa#diff-223b98dc29906194b0c41eeb83d19e55664789c8f55eca639a20b3e9c6ccdf51R114-R132 |
|
||
To work around this limitation, we do a single big consumeBody around the entire request | ||
processing. This hopefully encompasses most users of the body stream. Any read operations | ||
inside this block are simply forwarded upstream. |
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.
Cool, this is great!
fd99aaa
to
fec7e83
Compare
Rebased on latest 4.1.x branch |
❌ Oracle Cloud CI 17 latest failed: https://ge.micronaut.io/s/cqqo3c6ixfpyi |
@graemerocher please review and merge |
…ad-body' into andriy/function-http-tck-multiread-body # Conflicts: # gradle/libs.versions.toml # test-suite-http-server-tck-oraclecloud-function-http/build.gradle.kts
❌ Oracle Cloud CI 17 latest failed: https://ge.micronaut.io/s/52tpddmkuystm |
There are test failures |
This reverts commit 8121669.
seems there's still an issue with the FnBodyBinder, but that can be fixed in another pr. i've disabled the tck test again |
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
@graemerocher Can we merge? |
The proposed approach to do the same as in micronaut-projects/micronaut-gcp#1106 did not exactly work. This is because the
InputEvent
does not allow accessing theInputStream
directly. Instead it has a methodconsumeBody(Function<InputStream>)
that should be called with implementation similar to this:Because it closes the stream we cannot read the stream gradually and split it.
The solution is to read the stream as a whole into a byte array and then provide it to all the consumers. This will probably result in the same memory usage as in https://github.com/micronaut-projects/micronaut-gcp/pull/1106/files (since there we split each time and end up with one unused ByteBody caching the whole request). However, it will require reading the whole body before it is consumed (e.g. JSON parser cannot begin parsing the stream before whole body is read into memory).