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

Add a ByteBody-based write API #11078

Merged
merged 6 commits into from
Aug 13, 2024
Merged

Add a ByteBody-based write API #11078

merged 6 commits into from
Aug 13, 2024

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented Aug 13, 2024

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 ByteBodys to NettyByteBodys.
  • 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.

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.
@yawkat yawkat added the type: improvement A minor improvement to an existing feature label Aug 13, 2024
@yawkat yawkat added this to the 4.6.0 milestone Aug 13, 2024
@yawkat yawkat requested review from dstepanov and sdelamo August 13, 2024 07:15
yawkat added 3 commits August 13, 2024 09:16
# Conflicts:
#	http-server-netty/src/main/java/io/micronaut/http/server/netty/body/NettyBodyAdapter.java
package io.micronaut.http.body.stream;

import io.micronaut.core.annotation.Experimental;
import io.micronaut.core.annotation.NonNull;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.NonNull;

@sdelamo
Copy link
Contributor

sdelamo commented Aug 13, 2024

@yawkat can you check the sonar issues?

…pec.groovy

Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>
Copy link

* @since 4.6.0
*/
@Internal
public final class NettyBodyAdapter implements BufferConsumer.Upstream, Subscriber<ByteBuf> {
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

@yawkat 👆🏻

@sdelamo sdelamo merged commit e85f43d into 4.6.x Aug 13, 2024
17 checks passed
@sdelamo sdelamo deleted the stream-body branch August 13, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants