You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/09/12 12:39:02 UTC
[httpcomponents-core] 09/18: HTTPCORE-642: Implement
ConnectionFactory fluent builders
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-core.git
commit 4fce010129b88362268c6acfc5beb403b425ef68
Author: Carter Kozak <c4...@gmail.com>
AuthorDate: Wed Jul 29 17:40:09 2020 -0400
HTTPCORE-642: Implement ConnectionFactory fluent builders
This closes #208
---
.../io/DefaultBHttpClientConnectionFactory.java | 66 +++++++++++++++++++
.../io/DefaultBHttpServerConnectionFactory.java | 73 ++++++++++++++++++++++
2 files changed, 139 insertions(+)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
index e9781df..37c2e48 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
@@ -106,4 +106,70 @@ public class DefaultBHttpClientConnectionFactory
return conn;
}
+ /**
+ * Create a new {@link Builder}.
+ *
+ * @since 5.1
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder for {@link DefaultBHttpClientConnectionFactory}.
+ *
+ * @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 DefaultBHttpClientConnectionFactory build() {
+ return new DefaultBHttpClientConnectionFactory(
+ http1Config,
+ charCodingConfig,
+ incomingContentLengthStrategy,
+ outgoingContentLengthStrategy,
+ requestWriterFactory,
+ responseParserFactory);
+ }
+ }
}
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
index d74c528..8a67f1e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
@@ -107,4 +107,77 @@ public class DefaultBHttpServerConnectionFactory implements HttpConnectionFactor
return conn;
}
+ /**
+ * Create a new {@link Builder}.
+ *
+ * @since 5.1
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder for {@link DefaultBHttpServerConnectionFactory}.
+ *
+ * @since 5.1
+ */
+ public static final class Builder {
+ private String scheme;
+ private Http1Config http1Config;
+ private CharCodingConfig charCodingConfig;
+ private ContentLengthStrategy incomingContentLengthStrategy;
+ private ContentLengthStrategy outgoingContentLengthStrategy;
+ private HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory;
+ private HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory;
+
+ private Builder() {}
+
+ public Builder scheme(final String scheme) {
+ this.scheme = scheme;
+ return this;
+ }
+
+ 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 requestParserFactory(
+ final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory) {
+ this.requestParserFactory = requestParserFactory;
+ return this;
+ }
+
+ public Builder responseWriterFactory(
+ final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
+ this.responseWriterFactory = responseWriterFactory;
+ return this;
+ }
+
+ public DefaultBHttpServerConnectionFactory build() {
+ return new DefaultBHttpServerConnectionFactory(
+ scheme,
+ http1Config,
+ charCodingConfig,
+ incomingContentLengthStrategy,
+ outgoingContentLengthStrategy,
+ requestParserFactory,
+ responseWriterFactory);
+ }
+ }
}