Skip to content

Commit 5b7ae6a

Browse files
committed
Final changes for AsyncHttpClient#258.
When dealing with http expectations, check to see if we're writing a file and if so, set the content-length then as the FileBodyHandler invocation is delayed in this scenario.
1 parent 6ce7fb0 commit 5b7ae6a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

providers/grizzly/src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ boolean sendRequest(final FilterChainContext ctx,
543543
BodyHandler handler = bodyHandlerFactory.getBodyHandler(request);
544544
if (requestPacket.getHeaders().contains(Header.Expect)
545545
&& requestPacket.getHeaders().getValue(1).equalsIgnoreCase("100-Continue")) {
546+
// We have to set the content-length now as the headers will be flushed
547+
// before the FileBodyHandler is invoked. If we don't do it here, and
548+
// the user didn't explicitly set the length, then the transfer-encoding
549+
// will be chunked and zero-copy file transfer will not occur.
550+
final File f = request.getFile();
551+
if (f != null) {
552+
requestPacket.setContentLengthLong(f.length());
553+
}
546554
handler = new ExpectHandler(handler);
547555
}
548556
context.bodyHandler = handler;
@@ -2219,9 +2227,7 @@ public boolean doHandle(final FilterChainContext ctx,
22192227
final File f = request.getFile();
22202228
requestPacket.setContentLengthLong(f.length());
22212229
final HttpTransactionContext context = getHttpTransactionContext(ctx.getConnection());
2222-
if (!SEND_FILE_SUPPORT
2223-
|| requestPacket.isSecure()
2224-
|| requestPacket.getHeaders().contains(Header.TransferEncoding)) {
2230+
if (!SEND_FILE_SUPPORT || requestPacket.isSecure()) {
22252231
final FileInputStream fis = new FileInputStream(request.getFile());
22262232
final MemoryManager mm = ctx.getMemoryManager();
22272233
AtomicInteger written = new AtomicInteger();

0 commit comments

Comments
 (0)