Description
The HTTP specification encourages the usage of the Content-Length
field, but does not enforce it (RFC2616: "Applications SHOULD use this field to indicate the transfer-length of the message-body....").
A PartSource can return -1 as the length of this part to indicate a unknown size of this part. The static method getLengthOfParts
in com.ning.http.multipart.Part is already handling this case by stopping size calculation if one of the parts returns a value < 0 and returns -1 itself.
But the method construct()
in com.ning.http.client.providers.netty.NettyAsyncHttpProvider always sets the Content-Length field and thus sets the header to the invalid value Content-Length: -1
:
} else if (request.getParts() != null) {
MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders());
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType());
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength()));
} else if (request.getEntityWriter() != null) {
Instead, this code should check the content-length for a value > 0 and only set the header in this case:
} else if (request.getParts() != null) {
MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders());
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType());
if(mre.getContentLength() >= 0) {
nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength()));
}
} else if (request.getEntityWriter() != null) {