@@ -467,8 +467,11 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
467
467
} else {
468
468
nettyRequest .setHeader (HttpHeaders .Names .TRANSFER_ENCODING , HttpHeaders .Values .CHUNKED );
469
469
}
470
- } else {
471
- body = null ;
470
+
471
+ } else if (future .getRequest ().getParts () != null ) {
472
+ String contentType = nettyRequest .getHeader (HttpHeaders .Names .CONTENT_TYPE );
473
+ String length = nettyRequest .getHeader (HttpHeaders .Names .CONTENT_LENGTH );
474
+ body = new MultipartBody (future .getRequest ().getParts (), contentType , length );
472
475
}
473
476
}
474
477
@@ -512,7 +515,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
512
515
513
516
ChannelFuture writeFuture ;
514
517
if (ssl ) {
515
- writeFuture = channel .write (new ChunkedFile (raf , 0 , fileLength , 8192 ));
518
+ writeFuture = channel .write (new ChunkedFile (raf , 0 , fileLength , MAX_BUFFERED_BYTES ));
516
519
} else {
517
520
final FileRegion region = new OptimizedFileRegion (raf , 0 , fileLength );
518
521
writeFuture = channel .write (region );
@@ -536,15 +539,7 @@ public void operationComplete(ChannelFuture cf) {
536
539
}
537
540
throw ex ;
538
541
}
539
- } else if (body != null || future .getRequest ().getParts () != null ) {
540
- /**
541
- * TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements.
542
- */
543
- if (future .getRequest ().getParts () != null ) {
544
- String contentType = nettyRequest .getHeader (HttpHeaders .Names .CONTENT_TYPE );
545
- String length = nettyRequest .getHeader (HttpHeaders .Names .CONTENT_LENGTH );
546
- body = new MultipartBody (future .getRequest ().getParts (), contentType , length );
547
- }
542
+ } else if (body != null ) {
548
543
549
544
ChannelFuture writeFuture ;
550
545
if (!ssl && body instanceof RandomAccessBody ) {
@@ -816,28 +811,13 @@ else if (uri.getRawQuery() != null)
816
811
}
817
812
818
813
} else if (request .getParts () != null ) {
819
- int length = computeAndSetContentLength (request , nettyRequest );
820
-
821
- if (length == -1 ) {
822
- length = MAX_BUFFERED_BYTES ;
823
- }
824
-
825
814
MultipartRequestEntity mre = AsyncHttpProviderUtils .createMultipartRequestEntity (request .getParts (), request .getHeaders ());
826
815
827
816
nettyRequest .setHeader (HttpHeaders .Names .CONTENT_TYPE , mre .getContentType ());
828
817
nettyRequest .setHeader (HttpHeaders .Names .CONTENT_LENGTH , String .valueOf (mre .getContentLength ()));
829
818
830
- /**
831
- * TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements.
832
- */
833
-
834
- if (isSecure (uri )) {
835
- ChannelBuffer b = ChannelBuffers .dynamicBuffer (length );
836
- mre .writeRequest (new ChannelBufferOutputStream (b ));
837
- nettyRequest .setContent (b );
838
- }
839
819
} else if (request .getEntityWriter () != null ) {
840
- int length = computeAndSetContentLength (request , nettyRequest );
820
+ int length = getPredefinedContentLength (request , nettyRequest );
841
821
842
822
if (length == -1 ) {
843
823
length = MAX_BUFFERED_BYTES ;
@@ -1626,15 +1606,12 @@ protected static boolean abortOnWriteCloseException(Throwable cause) {
1626
1606
return false ;
1627
1607
}
1628
1608
1629
- private final static int computeAndSetContentLength (Request request , HttpRequest r ) {
1609
+ private final static int getPredefinedContentLength (Request request , HttpRequest r ) {
1630
1610
int length = (int ) request .getContentLength ();
1631
1611
if (length == -1 && r .getHeader (HttpHeaders .Names .CONTENT_LENGTH ) != null ) {
1632
1612
length = Integer .valueOf (r .getHeader (HttpHeaders .Names .CONTENT_LENGTH ));
1633
1613
}
1634
1614
1635
- if (length >= 0 ) {
1636
- r .setHeader (HttpHeaders .Names .CONTENT_LENGTH , String .valueOf (length ));
1637
- }
1638
1615
return length ;
1639
1616
}
1640
1617
0 commit comments