-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add a ByteBody-based write API #11078
Conversation
This PR adds a NettyWriteContext.write(HttpResponse, ByteBody) API that, in the long term, should replace all the other write methods (except the headResponse one). The advantage is that we can get rid of reactive code for streaming, and merge some code paths. These are the modifications: - `StreamingNettyByteBody` exposes its `primary` method to allow the HTTP writers direct access to the data using the internal byte streaming API. - `NettyBodyAdapter` is added to transform generic `ByteBody`s to `NettyByteBody`s. - `AvailableByteArrayBody` and `InputStreamByteBody` are moved here from micronaut-servlet and made `@Experimental`. - The `InputStream` based write method is removed from NettyWriteContext and replaced with `InputStreamByteBody`. This gets rid of a bunch of code.
# Conflicts: # http-server-netty/src/main/java/io/micronaut/http/server/netty/body/NettyBodyAdapter.java
...server-netty/src/test/groovy/io/micronaut/http/server/netty/body/NettyBodyAdapterSpec.groovy
Outdated
Show resolved
Hide resolved
package io.micronaut.http.body.stream; | ||
|
||
import io.micronaut.core.annotation.Experimental; | ||
import io.micronaut.core.annotation.NonNull; |
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.
import io.micronaut.core.annotation.NonNull; | |
import io.micronaut.core.annotation.Internal; | |
import io.micronaut.core.annotation.NonNull; |
http/src/main/java/io/micronaut/http/body/stream/AvailableByteArrayBody.java
Show resolved
Hide resolved
http/src/test/groovy/io/micronaut/http/body/stream/StreamPairSpec.groovy
Outdated
Show resolved
Hide resolved
@yawkat can you check the sonar issues? |
…pec.groovy Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>
Quality Gate passedIssues Measures |
* @since 4.6.0 | ||
*/ | ||
@Internal | ||
public final class NettyBodyAdapter implements BufferConsumer.Upstream, Subscriber<ByteBuf> { |
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.
Can some of those classes be package private?
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.
@yawkat 👆🏻
This PR adds a NettyWriteContext.write(HttpResponse, ByteBody) API that, in the long term, should replace all the other write methods (except the headResponse one). The advantage is that we can get rid of reactive code for streaming, and merge some code paths.
These are the modifications:
StreamingNettyByteBody
exposes itsprimary
method to allow the HTTP writers direct access to the data using the internal byte streaming API.NettyBodyAdapter
is added to transform genericByteBody
s toNettyByteBody
s.AvailableByteArrayBody
andInputStreamByteBody
are moved here from micronaut-servlet and made@Experimental
.InputStream
based write method is removed from NettyWriteContext and replaced withInputStreamByteBody
. This gets rid of a bunch of code.