4.x: Allow Unbuffered OutputStream for Http1ServerResponse (#9276) #9277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, when building a new
WebServer
instance, one can specifywriteBufferSize(0)
. The server builds and starts normally, but any http1 request handler that tries to useServerResponse.outputStream()
will throw an exception. This is obviously not very user friendly, and we should either fail when trying to build/start the server instance or support unbuffered responseOutputStream
s.I propose the latter approach, as it was the default before #6509 was merged. An obvious use case for unbuffered response writer is if the user does their own buffer management. For example, I'm currently moving an existing project to Helidon, which uses its own buffer pool to reduce GC pressure. Not allowing a buffer size of
0
would mean that there is no way to avoid the allocation of a new buffer for every request.Solves issue #9276
Documentation
I added a new abstract class
ResponseOutputStream
inHttp1ServerResponse
, which serves as a base for the two existing classesBlockingOutputStream
andClosingBufferedOutputStream
. That way, we can choose which one to use after checking the write buffer size.I also added the
WriteBufferTest
class to test both the default and zero write buffer case.