Skip to content

Commit 0097294

Browse files
author
Stephane Landelle
committed
Netty provider sends parts twice over https, port a29f682 to master
1 parent 7b857cf commit 0097294

File tree

2 files changed

+8
-47
lines changed

2 files changed

+8
-47
lines changed

api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java

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

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

136-
/*
137-
* (non-Javadoc)
138-
*
139-
* @see org.apache.commons.httpclient.methods.RequestEntity#getContentLength()
140-
*/
141131
public long getContentLength() {
142132
try {
143133
return Part.getLengthOfParts(parts, multipartBoundary);
@@ -147,11 +137,6 @@ public long getContentLength() {
147137
}
148138
}
149139

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

providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,10 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
428428
} else {
429429
nettyRequest.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
430430
}
431-
} else {
432-
body = null;
431+
} else if (future.getRequest().getParts() != null) {
432+
String contentType = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_TYPE);
433+
String length = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_LENGTH);
434+
body = new MultipartBody(future.getRequest().getParts(), contentType, length);
433435
}
434436
}
435437

@@ -473,7 +475,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
473475

474476
ChannelFuture writeFuture;
475477
if (channel.getPipeline().get(SslHandler.class) != null) {
476-
writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, 8192));
478+
writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, MAX_BUFFERED_BYTES));
477479
} else {
478480
final FileRegion region = new OptimizedFileRegion(raf, 0, fileLength);
479481
writeFuture = channel.write(region);
@@ -497,15 +499,7 @@ public void operationComplete(ChannelFuture cf) {
497499
}
498500
throw ex;
499501
}
500-
} else if (body != null || future.getRequest().getParts() != null) {
501-
/**
502-
* TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements.
503-
*/
504-
if (future.getRequest().getParts() != null) {
505-
String contentType = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_TYPE);
506-
String length = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_LENGTH);
507-
body = new MultipartBody(future.getRequest().getParts(), contentType, length);
508-
}
502+
} else if (body != null) {
509503

510504
ChannelFuture writeFuture;
511505
if (channel.getPipeline().get(SslHandler.class) == null && (body instanceof RandomAccessBody)) {
@@ -792,28 +786,13 @@ else if (uri.getRawQuery() != null)
792786
}
793787

794788
} else if (request.getParts() != null) {
795-
int length = computeAndSetContentLength(request, nettyRequest);
796-
797-
if (length == -1) {
798-
length = MAX_BUFFERED_BYTES;
799-
}
800-
801789
MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders());
802790

803791
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType());
804792
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength()));
805793

806-
/**
807-
* TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements.
808-
*/
809-
810-
if (isSecure(uri)) {
811-
ChannelBuffer b = ChannelBuffers.dynamicBuffer(length);
812-
mre.writeRequest(new ChannelBufferOutputStream(b));
813-
nettyRequest.setContent(b);
814-
}
815794
} else if (request.getEntityWriter() != null) {
816-
int length = computeAndSetContentLength(request, nettyRequest);
795+
int length = getPredefinedContentLength(request, nettyRequest);
817796

818797
if (length == -1) {
819798
length = MAX_BUFFERED_BYTES;
@@ -1580,15 +1559,12 @@ protected static boolean abortOnWriteCloseException(Throwable cause) {
15801559
return false;
15811560
}
15821561

1583-
private final static int computeAndSetContentLength(Request request, HttpRequest r) {
1562+
private final static int getPredefinedContentLength(Request request, HttpRequest r) {
15841563
int length = (int) request.getContentLength();
15851564
if (length == -1 && r.getHeader(HttpHeaders.Names.CONTENT_LENGTH) != null) {
15861565
length = Integer.valueOf(r.getHeader(HttpHeaders.Names.CONTENT_LENGTH));
15871566
}
15881567

1589-
if (length >= 0) {
1590-
r.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(length));
1591-
}
15921568
return length;
15931569
}
15941570

0 commit comments

Comments
 (0)