[prev in list] [next in list] [prev in thread] [next in thread]
List: httpcomponents-commits
Subject: [httpcomponents-client] 01/08: HTTPCLIENT-2103: ManagedHttpClientConnectionFactory provides a fluent
From: olegk () apache ! org
Date: 2020-09-27 10:42:19
Message-ID: 20200927104218.D048C82908 () gitbox ! apache ! org
[Download RAW message or body]
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 1a70490aac71621d4b17f0fe4488df34a782b2e5
Author: Carter Kozak <ckozak@apache.org>
AuthorDate: Tue Aug 4 15:06:34 2020 -0400
HTTPCLIENT-2103: ManagedHttpClientConnectionFactory provides a fluent builder
---
.../hc/client5/http/impl/classic/ProxyClient.java | 7 ++-
.../io/ManagedHttpClientConnectionFactory.java | 67 ++++++++++++++++++++++
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java \
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java \
index ef7a5ea..fa01137 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java
@@ -104,7 +104,12 @@ public class ProxyClient {
final CharCodingConfig charCodingConfig,
final RequestConfig requestConfig) {
super();
- this.connFactory = connFactory != null ? connFactory : new \
ManagedHttpClientConnectionFactory(h1Config, charCodingConfig, null, null); + \
this.connFactory = connFactory != null + ? connFactory
+ : ManagedHttpClientConnectionFactory.builder()
+ .http1Config(h1Config)
+ .charCodingConfig(charCodingConfig)
+ .build();
this.requestConfig = requestConfig != null ? requestConfig : \
RequestConfig.DEFAULT; this.httpProcessor = new DefaultHttpProcessor(
new RequestTargetHost(), new RequestClientConnControl(), new \
RequestUserAgent());
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java \
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
index 63ae378..cce30ca 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
@@ -139,4 +139,71 @@ public class ManagedHttpClientConnectionFactory implements \
HttpConnectionFactory return conn;
}
+ /**
+ * Create a new {@link Builder}.
+ *
+ * @since 5.1
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder for {@link ManagedHttpClientConnectionFactory}.
+ *
+ * @since 5.1
+ */
+ public static final class Builder {
+
+ private Http1Config http1Config;
+ private CharCodingConfig charCodingConfig;
+ private ContentLengthStrategy incomingContentLengthStrategy;
+ private ContentLengthStrategy outgoingContentLengthStrategy;
+ private HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory;
+ private HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory;
+
+ private Builder() {}
+
+ public Builder http1Config(final Http1Config http1Config) {
+ this.http1Config = http1Config;
+ return this;
+ }
+
+ public Builder charCodingConfig(final CharCodingConfig charCodingConfig) {
+ this.charCodingConfig = charCodingConfig;
+ return this;
+ }
+
+ public Builder incomingContentLengthStrategy(final ContentLengthStrategy \
incomingContentLengthStrategy) { + this.incomingContentLengthStrategy = \
incomingContentLengthStrategy; + return this;
+ }
+
+ public Builder outgoingContentLengthStrategy(final ContentLengthStrategy \
outgoingContentLengthStrategy) { + this.outgoingContentLengthStrategy = \
outgoingContentLengthStrategy; + return this;
+ }
+
+ public Builder requestWriterFactory(
+ final HttpMessageWriterFactory<ClassicHttpRequest> \
requestWriterFactory) { + this.requestWriterFactory = \
requestWriterFactory; + return this;
+ }
+
+ public Builder responseParserFactory(
+ final HttpMessageParserFactory<ClassicHttpResponse> \
responseParserFactory) { + this.responseParserFactory = \
responseParserFactory; + return this;
+ }
+
+ public ManagedHttpClientConnectionFactory build() {
+ return new ManagedHttpClientConnectionFactory(
+ http1Config,
+ charCodingConfig,
+ requestWriterFactory,
+ responseParserFactory,
+ incomingContentLengthStrategy,
+ outgoingContentLengthStrategy);
+ }
+ }
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic