Skip to content

Commit 0c1e18b

Browse files
committed
Changing LAST_HTTP_CONTENT_RECEIVED_KEY key name to STREAMING_COMPLETE_KEY and setting it irrespective of ignoreBodyRead flag
1 parent 267eee9 commit 0c1e18b

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/ChannelAttributeKey.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ public final class ChannelAttributeKey {
7474
"aws.http.nio.netty.async.channelDiagnostics");
7575

7676
/**
77-
* {@link AttributeKey} to keep track of whether we have received the {@link LastHttpContent}.
77+
* {@link AttributeKey} to keep track of whether the streaming is completed and this is set to true when we receive the *
78+
* {@link LastHttpContent}.
7879
*/
79-
public static final AttributeKey<Boolean> LAST_HTTP_CONTENT_RECEIVED_KEY = NettyUtils.getOrCreateAttributeKey(
80-
"aws.http.nio.netty.async.lastHttpContentReceived");
80+
public static final AttributeKey<Boolean> STREAMING_COMPLETE_KEY = NettyUtils.getOrCreateAttributeKey(
81+
"aws.http.nio.netty.async.streamingCompleted");
8182

8283
/**
8384
* {@link AttributeKey} to keep track of whether we should close the connection after this request

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/NettyRequestExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.EXECUTION_ID_KEY;
2222
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.IN_USE;
2323
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.KEEP_ALIVE;
24-
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.LAST_HTTP_CONTENT_RECEIVED_KEY;
24+
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.STREAMING_COMPLETE_KEY;
2525
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.REQUEST_CONTEXT_KEY;
2626
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.RESPONSE_COMPLETE_KEY;
2727
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.RESPONSE_CONTENT_LENGTH;
@@ -195,7 +195,7 @@ private void configureChannel() {
195195
channel.attr(EXECUTE_FUTURE_KEY).set(executeFuture);
196196
channel.attr(REQUEST_CONTEXT_KEY).set(context);
197197
channel.attr(RESPONSE_COMPLETE_KEY).set(false);
198-
channel.attr(LAST_HTTP_CONTENT_RECEIVED_KEY).set(false);
198+
channel.attr(STREAMING_COMPLETE_KEY).set(false);
199199
channel.attr(RESPONSE_CONTENT_LENGTH).set(null);
200200
channel.attr(RESPONSE_DATA_READ).set(null);
201201
channel.attr(CHANNEL_DIAGNOSTICS).get().incrementRequestCount();

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/ResponseHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static java.util.stream.Collectors.mapping;
2020
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.EXECUTE_FUTURE_KEY;
2121
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.KEEP_ALIVE;
22-
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.LAST_HTTP_CONTENT_RECEIVED_KEY;
22+
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.STREAMING_COMPLETE_KEY;
2323
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.REQUEST_CONTEXT_KEY;
2424
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.RESPONSE_COMPLETE_KEY;
2525
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.RESPONSE_CONTENT_LENGTH;
@@ -463,10 +463,10 @@ public void cancel() {
463463
private void notifyIfResponseNotCompleted(ChannelHandlerContext handlerCtx) {
464464
RequestContext requestCtx = handlerCtx.channel().attr(REQUEST_CONTEXT_KEY).get();
465465
Boolean responseCompleted = handlerCtx.channel().attr(RESPONSE_COMPLETE_KEY).get();
466-
Boolean lastHttpContentReceived = handlerCtx.channel().attr(LAST_HTTP_CONTENT_RECEIVED_KEY).get();
466+
Boolean isStreamingComplete = handlerCtx.channel().attr(STREAMING_COMPLETE_KEY).get();
467467
handlerCtx.channel().attr(KEEP_ALIVE).set(false);
468468

469-
if (!Boolean.TRUE.equals(responseCompleted) && !Boolean.TRUE.equals(lastHttpContentReceived)) {
469+
if (!Boolean.TRUE.equals(responseCompleted) && !Boolean.TRUE.equals(isStreamingComplete)) {
470470
IOException err = new IOException(NettyUtils.closedChannelMessage(handlerCtx.channel()));
471471
runAndLogError(handlerCtx.channel(), () -> "Fail to execute SdkAsyncHttpResponseHandler#onError",
472472
() -> requestCtx.handler().onError(err));

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/nrs/HttpStreamsHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package software.amazon.awssdk.http.nio.netty.internal.nrs;
1717

18-
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.LAST_HTTP_CONTENT_RECEIVED_KEY;
18+
import static software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.STREAMING_COMPLETE_KEY;
1919

2020
import io.netty.channel.ChannelDuplexHandler;
2121
import io.netty.channel.ChannelFuture;
@@ -213,9 +213,12 @@ private void handleCancelled(ChannelHandlerContext ctx, InT msg) {
213213
}
214214

215215
private void handleReadHttpContent(ChannelHandlerContext ctx, HttpContent content) {
216+
boolean lastHttpContent = content instanceof LastHttpContent;
217+
if(lastHttpContent){
218+
ctx.channel().attr(STREAMING_COMPLETE_KEY).set(true);
219+
}
216220
if (!ignoreBodyRead) {
217-
if (content instanceof LastHttpContent) {
218-
ctx.channel().attr(LAST_HTTP_CONTENT_RECEIVED_KEY).set(true);
221+
if (lastHttpContent) {
219222
logger.debug(ctx.channel(), () -> "Received LastHttpContent " + ctx.channel());
220223
if (content.content().readableBytes() > 0 ||
221224
!((LastHttpContent) content).trailingHeaders().isEmpty()) {
@@ -235,7 +238,7 @@ private void handleReadHttpContent(ChannelHandlerContext ctx, HttpContent conten
235238

236239
} else {
237240
ReferenceCountUtil.release(content);
238-
if (content instanceof LastHttpContent) {
241+
if (lastHttpContent) {
239242
ignoreBodyRead = false;
240243
if (currentlyStreamedMessage != null) {
241244
removeHandlerIfActive(ctx, ctx.name() + "-body-publisher");

0 commit comments

Comments
 (0)