diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java b/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java index 7f4b04360..2d7d521dc 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java @@ -42,6 +42,9 @@ import org.apache.http.config.ConnectionConfig; import org.apache.http.conn.HttpConnectionFactory; import org.apache.http.conn.ManagedHttpClientConnection; import org.apache.http.conn.routing.HttpRoute; +import org.apache.http.entity.ContentLengthStrategy; +import org.apache.http.impl.entity.LaxContentLengthStrategy; +import org.apache.http.impl.entity.StrictContentLengthStrategy; import org.apache.http.impl.io.DefaultHttpRequestWriterFactory; import org.apache.http.io.HttpMessageParserFactory; import org.apache.http.io.HttpMessageWriterFactory; @@ -64,15 +67,32 @@ public class ManagedHttpClientConnectionFactory private final HttpMessageWriterFactory requestWriterFactory; private final HttpMessageParserFactory responseParserFactory; + private final ContentLengthStrategy incomingContentStrategy; + private final ContentLengthStrategy outgoingContentStrategy; + + /** + * @since 4.4 + */ + public ManagedHttpClientConnectionFactory( + final HttpMessageWriterFactory requestWriterFactory, + final HttpMessageParserFactory responseParserFactory, + final ContentLengthStrategy incomingContentStrategy, + final ContentLengthStrategy outgoingContentStrategy) { + super(); + this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory : + DefaultHttpRequestWriterFactory.INSTANCE; + this.responseParserFactory = responseParserFactory != null ? responseParserFactory : + DefaultHttpResponseParserFactory.INSTANCE; + this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy : + LaxContentLengthStrategy.INSTANCE; + this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy : + StrictContentLengthStrategy.INSTANCE; + } public ManagedHttpClientConnectionFactory( final HttpMessageWriterFactory requestWriterFactory, final HttpMessageParserFactory responseParserFactory) { - super(); - this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory : - DefaultHttpRequestWriterFactory.INSTANCE; - this.responseParserFactory = responseParserFactory != null ? responseParserFactory : - DefaultHttpResponseParserFactory.INSTANCE; + this(requestWriterFactory, responseParserFactory, null, null); } public ManagedHttpClientConnectionFactory( @@ -113,8 +133,8 @@ public class ManagedHttpClientConnectionFactory chardecoder, charencoder, cconfig.getMessageConstraints(), - null, - null, + incomingContentStrategy, + outgoingContentStrategy, requestWriterFactory, responseParserFactory); }