Skip to content

Commit a29f682

Browse files
author
Stephane Landelle
committed
Netty provider sends parts twice over https
1 parent 223641f commit a29f682

File tree

2 files changed

+9
-48
lines changed

2 files changed

+9
-48
lines changed

src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,11 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
467467
} else {
468468
nettyRequest.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
469469
}
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);
472475
}
473476
}
474477

@@ -512,7 +515,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
512515

513516
ChannelFuture writeFuture;
514517
if (ssl) {
515-
writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, 8192));
518+
writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, MAX_BUFFERED_BYTES));
516519
} else {
517520
final FileRegion region = new OptimizedFileRegion(raf, 0, fileLength);
518521
writeFuture = channel.write(region);
@@ -536,15 +539,7 @@ public void operationComplete(ChannelFuture cf) {
536539
}
537540
throw ex;
538541
}
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) {
548543

549544
ChannelFuture writeFuture;
550545
if (!ssl && body instanceof RandomAccessBody) {
@@ -816,28 +811,13 @@ else if (uri.getRawQuery() != null)
816811
}
817812

818813
} else if (request.getParts() != null) {
819-
int length = computeAndSetContentLength(request, nettyRequest);
820-
821-
if (length == -1) {
822-
length = MAX_BUFFERED_BYTES;
823-
}
824-
825814
MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders());
826815

827816
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType());
828817
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength()));
829818

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-
}
839819
} else if (request.getEntityWriter() != null) {
840-
int length = computeAndSetContentLength(request, nettyRequest);
820+
int length = getPredefinedContentLength(request, nettyRequest);
841821

842822
if (length == -1) {
843823
length = MAX_BUFFERED_BYTES;
@@ -1626,15 +1606,12 @@ protected static boolean abortOnWriteCloseException(Throwable cause) {
16261606
return false;
16271607
}
16281608

1629-
private final static int computeAndSetContentLength(Request request, HttpRequest r) {
1609+
private final static int getPredefinedContentLength(Request request, HttpRequest r) {
16301610
int length = (int) request.getContentLength();
16311611
if (length == -1 && r.getHeader(HttpHeaders.Names.CONTENT_LENGTH) != null) {
16321612
length = Integer.valueOf(r.getHeader(HttpHeaders.Names.CONTENT_LENGTH));
16331613
}
16341614

1635-
if (length >= 0) {
1636-
r.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(length));
1637-
}
16381615
return length;
16391616
}
16401617

src/main/java/com/ning/http/multipart/MultipartRequestEntity.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,10 @@ public boolean isRepeatable() {
125125
return true;
126126
}
127127

128-
/*
129-
* (non-Javadoc)
130-
*
131-
* @see org.apache.commons.httpclient.methods.RequestEntity#writeRequest(java.io.OutputStream)
132-
*/
133128
public void writeRequest(OutputStream out) throws IOException {
134129
Part.sendParts(out, parts, multipartBoundary);
135130
}
136131

137-
/*
138-
* (non-Javadoc)
139-
*
140-
* @see org.apache.commons.httpclient.methods.RequestEntity#getContentLength()
141-
*/
142132
public long getContentLength() {
143133
try {
144134
return Part.getLengthOfParts(parts, multipartBoundary);
@@ -148,13 +138,7 @@ public long getContentLength() {
148138
}
149139
}
150140

151-
/*
152-
* (non-Javadoc)
153-
*
154-
* @see org.apache.commons.httpclient.methods.RequestEntity#getContentType()
155-
*/
156141
public String getContentType() {
157142
return contentType;
158143
}
159144
}
160-

0 commit comments

Comments
 (0)