Skip to content

Commit 858652c

Browse files
committed
Reusing ReadTimeoutHandler for 100continueExpected request
1 parent f2496bf commit 858652c

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,18 @@ private void writeRequest(HttpRequest request) {
169169
// Done writing so remove the idle write timeout handler
170170
ChannelUtils.removeIfExists(channel.pipeline(), WriteTimeoutHandler.class);
171171
if (wireCall.isSuccess()) {
172-
if (!context.executeRequest().fullDuplex()) {
173-
// Starting read so add the idle read timeout handler, removed when channel is released
172+
if (context.executeRequest().fullDuplex()) {
173+
return;
174+
}
175+
176+
// if it is 100ContinueExpected request, then we do not need to add another ReadTimeoutHandler
177+
if (!is100ContinueExpected()) {
174178
channel.pipeline().addFirst(new ReadTimeoutHandler(context.configuration().readTimeoutMillis(),
175179
TimeUnit.MILLISECONDS));
176-
channel.read();
177180
}
181+
182+
channel.read();
183+
178184
} else {
179185
// TODO: Are there cases where we can keep the channel open?
180186
closeAndRelease(channel);
@@ -198,11 +204,15 @@ private void writeRequest(HttpRequest request) {
198204
* @return true if it should explicitly read from channel
199205
*/
200206
private boolean shouldExplicitlyTriggerRead() {
201-
boolean is100ContinueExpected = context.executeRequest().request()
202-
.firstMatchingHeader("Expect")
203-
.filter(b -> b.equalsIgnoreCase("100-continue")).isPresent();
207+
return context.executeRequest().fullDuplex() || is100ContinueExpected();
208+
}
204209

205-
return context.executeRequest().fullDuplex() || is100ContinueExpected;
210+
private boolean is100ContinueExpected() {
211+
return context.executeRequest()
212+
.request()
213+
.firstMatchingHeader("Expect")
214+
.filter(b -> b.equalsIgnoreCase("100-continue"))
215+
.isPresent();
206216
}
207217

208218
private URI endpoint() {

0 commit comments

Comments
 (0)