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 2022/07/08 17:11:15 UTC
[httpcomponents-client] branch master updated: Avoid duplicate redundant objects and use Singleton instead.
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
The following commit(s) were added to refs/heads/master by this push:
new 18fa09f6a Avoid duplicate redundant objects and use Singleton instead.
18fa09f6a is described below
commit 18fa09f6a2d760b1c8ff0debb5bc04562dfe9ee1
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Tue Jul 5 21:13:44 2022 +0200
Avoid duplicate redundant objects and use Singleton instead.
---
.../hc/client5/http/cookie/BasicCookieStore.java | 2 +-
.../http/cookie/CookieIdentityComparator.java | 7 +++
.../client5/http/impl/async/AsyncConnectExec.java | 2 +-
.../http/impl/async/H2AsyncClientBuilder.java | 4 +-
.../http/impl/async/HttpAsyncClientBuilder.java | 4 +-
.../hc/client5/http/impl/classic/ConnectExec.java | 2 +-
.../http/impl/classic/HttpClientBuilder.java | 4 +-
.../http/impl/cookie/BasicDomainHandler.java | 8 +++
.../http/impl/cookie/BasicHttpOnlyHandler.java | 7 +++
.../http/impl/cookie/BasicMaxAgeHandler.java | 7 +++
.../client5/http/impl/cookie/BasicPathHandler.java | 7 +++
.../http/impl/cookie/BasicSecureHandler.java | 7 +++
.../http/impl/cookie/IgnoreCookieSpecFactory.java | 2 +-
.../client5/http/impl/cookie/IgnoreSpecSpec.java | 7 +++
.../http/impl/cookie/LaxExpiresHandler.java | 7 +++
.../client5/http/impl/cookie/LaxMaxAgeHandler.java | 7 +++
.../http/impl/cookie/RFC6265CookieSpecFactory.java | 28 +++++-----
.../client5/http/impl/cookie/RFC6265LaxSpec.java | 12 ++--
.../http/impl/cookie/RFC6265StrictSpec.java | 10 ++--
.../http/impl/routing/BasicRouteDirector.java | 7 +++
.../client5/http/protocol/RequestAddCookies.java | 7 +++
.../http/protocol/RequestDefaultHeaders.java | 7 +++
.../http/protocol/ResponseProcessCookies.java | 7 +++
.../client5/http/psl/PublicSuffixListParser.java | 7 +++
.../http/psl/PublicSuffixMatcherLoader.java | 2 +-
.../impl/classic/TestCookieIdentityComparator.java | 10 ++--
.../impl/cookie/TestBasicCookieAttribHandlers.java | 54 +++++++++---------
.../impl/cookie/TestLaxCookieAttribHandlers.java | 64 +++++++++++-----------
.../impl/cookie/TestPublicSuffixListParser.java | 4 +-
.../http/impl/routing/TestRouteDirector.java | 14 ++---
.../http/impl/routing/TestRouteTracker.java | 6 +-
.../http/protocol/TestRequestAddCookies.java | 30 +++++-----
.../http/protocol/TestRequestDefaultHeaders.java | 2 +-
.../http/protocol/TestResponseProcessCookies.java | 12 ++--
.../http/psl/TestPublicSuffixListParser.java | 4 +-
.../client5/http/psl/TestPublicSuffixMatcher.java | 2 +-
.../http/ssl/TestDefaultHostnameVerifier.java | 2 +-
37 files changed, 237 insertions(+), 138 deletions(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/BasicCookieStore.java b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/BasicCookieStore.java
index 3f1001361..38b972c57 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/BasicCookieStore.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/BasicCookieStore.java
@@ -56,7 +56,7 @@ public class BasicCookieStore implements CookieStore, Serializable {
public BasicCookieStore() {
super();
- this.cookies = new TreeSet<>(new CookieIdentityComparator());
+ this.cookies = new TreeSet<>(CookieIdentityComparator.INSTANCE);
this.lock = new ReentrantReadWriteLock();
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookieIdentityComparator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookieIdentityComparator.java
index 2e007fdbf..a274e7242 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookieIdentityComparator.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookieIdentityComparator.java
@@ -45,6 +45,13 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
@Contract(threading = ThreadingBehavior.STATELESS)
public class CookieIdentityComparator implements Serializable, Comparator<Cookie> {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final CookieIdentityComparator INSTANCE = new CookieIdentityComparator();
+
private static final long serialVersionUID = 4466565437490631532L;
@Override
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncConnectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncConnectExec.java
index 77c20db0f..da534c91c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncConnectExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncConnectExec.java
@@ -100,7 +100,7 @@ public final class AsyncConnectExec implements AsyncExecChainHandler {
this.proxyAuthStrategy = proxyAuthStrategy;
this.authenticator = new HttpAuthenticator();
this.authCacheKeeper = authCachingDisabled ? null : new AuthCacheKeeper(schemePortResolver);
- this.routeDirector = new BasicRouteDirector();
+ this.routeDirector = BasicRouteDirector.INSTANCE;
}
static class State {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java
index c2ca48d86..d26b3aef8 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java
@@ -690,10 +690,10 @@ public class H2AsyncClientBuilder {
new RequestUserAgent(userAgentCopy),
new RequestExpectContinue());
if (!cookieManagementDisabled) {
- b.add(new RequestAddCookies());
+ b.add(RequestAddCookies.INSTANCE);
}
if (!cookieManagementDisabled) {
- b.add(new ResponseProcessCookies());
+ b.add(ResponseProcessCookies.INSTANCE);
}
if (requestInterceptors != null) {
for (final RequestInterceptorEntry entry: requestInterceptors) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
index c3e4de735..38a9b22f1 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
@@ -822,10 +822,10 @@ public class HttpAsyncClientBuilder {
new RequestUserAgent(userAgentCopy),
new RequestExpectContinue());
if (!cookieManagementDisabled) {
- b.add(new RequestAddCookies());
+ b.add(RequestAddCookies.INSTANCE);
}
if (!cookieManagementDisabled) {
- b.add(new ResponseProcessCookies());
+ b.add(ResponseProcessCookies.INSTANCE);
}
if (requestInterceptors != null) {
for (final RequestInterceptorEntry entry: requestInterceptors) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ConnectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ConnectExec.java
index df0eb4b37..56fee6aad 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ConnectExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ConnectExec.java
@@ -101,7 +101,7 @@ public final class ConnectExec implements ExecChainHandler {
this.proxyAuthStrategy = proxyAuthStrategy;
this.authenticator = new HttpAuthenticator();
this.authCacheKeeper = authCachingDisabled ? null : new AuthCacheKeeper(schemePortResolver);
- this.routeDirector = new BasicRouteDirector();
+ this.routeDirector = BasicRouteDirector.INSTANCE;
}
@Override
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java
index 2c9228181..b8d0d1037 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java
@@ -805,10 +805,10 @@ public class HttpClientBuilder {
new RequestUserAgent(userAgentCopy),
new RequestExpectContinue());
if (!cookieManagementDisabled) {
- b.add(new RequestAddCookies());
+ b.add(RequestAddCookies.INSTANCE);
}
if (!cookieManagementDisabled) {
- b.add(new ResponseProcessCookies());
+ b.add(ResponseProcessCookies.INSTANCE);
}
if (requestInterceptors != null) {
for (final RequestInterceptorEntry entry: requestInterceptors) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicDomainHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicDomainHandler.java
index fd3cc51b1..c4abd088b 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicDomainHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicDomainHandler.java
@@ -48,6 +48,14 @@ import org.apache.hc.core5.util.TextUtils;
@Contract(threading = ThreadingBehavior.STATELESS)
public class BasicDomainHandler implements CommonCookieAttributeHandler {
+
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final BasicDomainHandler INSTANCE = new BasicDomainHandler();
+
public BasicDomainHandler() {
super();
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicHttpOnlyHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicHttpOnlyHandler.java
index adb2067a7..700b582b3 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicHttpOnlyHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicHttpOnlyHandler.java
@@ -43,6 +43,13 @@ import org.apache.hc.core5.util.Args;
@Contract(threading = ThreadingBehavior.STATELESS)
public class BasicHttpOnlyHandler implements CommonCookieAttributeHandler {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final BasicHttpOnlyHandler INSTANCE = new BasicHttpOnlyHandler();
+
public BasicHttpOnlyHandler() {
super();
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicMaxAgeHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicMaxAgeHandler.java
index 07445a6f0..76f4558d1 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicMaxAgeHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicMaxAgeHandler.java
@@ -44,6 +44,13 @@ import org.apache.hc.core5.util.Args;
@Contract(threading = ThreadingBehavior.STATELESS)
public class BasicMaxAgeHandler extends AbstractCookieAttributeHandler implements CommonCookieAttributeHandler {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final BasicMaxAgeHandler INSTANCE = new BasicMaxAgeHandler();
+
public BasicMaxAgeHandler() {
super();
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicPathHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicPathHandler.java
index 693c455c4..23b1f5efc 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicPathHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicPathHandler.java
@@ -44,6 +44,13 @@ import org.apache.hc.core5.util.TextUtils;
@Contract(threading = ThreadingBehavior.STATELESS)
public class BasicPathHandler implements CommonCookieAttributeHandler {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final BasicPathHandler INSTANCE = new BasicPathHandler();
+
public BasicPathHandler() {
super();
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicSecureHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicSecureHandler.java
index e8a3060b4..13e37f1e1 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicSecureHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicSecureHandler.java
@@ -43,6 +43,13 @@ import org.apache.hc.core5.util.Args;
@Contract(threading = ThreadingBehavior.STATELESS)
public class BasicSecureHandler extends AbstractCookieAttributeHandler implements CommonCookieAttributeHandler {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final BasicSecureHandler INSTANCE = new BasicSecureHandler();
+
public BasicSecureHandler() {
super();
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreCookieSpecFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreCookieSpecFactory.java
index 38941ba83..a77fce707 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreCookieSpecFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreCookieSpecFactory.java
@@ -52,7 +52,7 @@ public class IgnoreCookieSpecFactory implements CookieSpecFactory {
if (cookieSpec == null) {
synchronized (this) {
if (cookieSpec == null) {
- this.cookieSpec = new IgnoreSpecSpec();
+ this.cookieSpec = IgnoreSpecSpec.INSTANCE;
}
}
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreSpecSpec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreSpecSpec.java
index 325f38763..3f8d0c4d9 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreSpecSpec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/IgnoreSpecSpec.java
@@ -45,6 +45,13 @@ import org.apache.hc.core5.http.Header;
@Contract(threading = ThreadingBehavior.STATELESS)
public class IgnoreSpecSpec extends CookieSpecBase {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final IgnoreSpecSpec INSTANCE = new IgnoreSpecSpec();
+
@Override
public List<Cookie> parse(final Header header, final CookieOrigin origin)
throws MalformedCookieException {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
index a81d61ee0..5afa9f106 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
@@ -56,6 +56,13 @@ import org.apache.hc.core5.util.Tokenizer;
@Contract(threading = ThreadingBehavior.STATELESS)
public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements CommonCookieAttributeHandler {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final LaxExpiresHandler INSTANCE = new LaxExpiresHandler();
+
private static final BitSet DELIMS;
static {
final BitSet bitSet = new BitSet();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxMaxAgeHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxMaxAgeHandler.java
index 7bf9a2131..19758e103 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxMaxAgeHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxMaxAgeHandler.java
@@ -48,6 +48,13 @@ import org.apache.hc.core5.util.TextUtils;
@Contract(threading = ThreadingBehavior.STATELESS)
public class LaxMaxAgeHandler extends AbstractCookieAttributeHandler implements CommonCookieAttributeHandler {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final LaxMaxAgeHandler INSTANCE = new LaxMaxAgeHandler();
+
private final static Pattern MAX_AGE_PATTERN = Pattern.compile("^\\-?[0-9]+$");
public LaxMaxAgeHandler() {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpecFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpecFactory.java
index 93575c25a..304ffafc8 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpecFactory.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265CookieSpecFactory.java
@@ -83,12 +83,12 @@ public class RFC6265CookieSpecFactory implements CookieSpecFactory {
switch (this.compatibilityLevel) {
case STRICT:
this.cookieSpec = new RFC6265StrictSpec(
- new BasicPathHandler(),
+ BasicPathHandler.INSTANCE,
PublicSuffixDomainFilter.decorate(
- new BasicDomainHandler(), this.publicSuffixMatcher),
- new BasicMaxAgeHandler(),
- new BasicSecureHandler(),
- new BasicHttpOnlyHandler(),
+ BasicDomainHandler.INSTANCE, this.publicSuffixMatcher),
+ BasicMaxAgeHandler.INSTANCE,
+ BasicSecureHandler.INSTANCE,
+ BasicHttpOnlyHandler.INSTANCE,
new BasicExpiresHandler(DateUtils.STANDARD_PATTERNS));
break;
case IE_MEDIUM_SECURITY:
@@ -102,20 +102,20 @@ public class RFC6265CookieSpecFactory implements CookieSpecFactory {
}
},
PublicSuffixDomainFilter.decorate(
- new BasicDomainHandler(), this.publicSuffixMatcher),
- new BasicMaxAgeHandler(),
- new BasicSecureHandler(),
- new BasicHttpOnlyHandler(),
+ BasicDomainHandler.INSTANCE, this.publicSuffixMatcher),
+ BasicMaxAgeHandler.INSTANCE,
+ BasicSecureHandler.INSTANCE,
+ BasicHttpOnlyHandler.INSTANCE,
new BasicExpiresHandler(DateUtils.STANDARD_PATTERNS));
break;
default:
this.cookieSpec = new RFC6265LaxSpec(
- new BasicPathHandler(),
+ BasicPathHandler.INSTANCE,
PublicSuffixDomainFilter.decorate(
- new BasicDomainHandler(), this.publicSuffixMatcher),
- new LaxMaxAgeHandler(),
- new BasicSecureHandler(),
- new LaxExpiresHandler());
+ BasicDomainHandler.INSTANCE, this.publicSuffixMatcher),
+ LaxMaxAgeHandler.INSTANCE,
+ BasicSecureHandler.INSTANCE,
+ LaxExpiresHandler.INSTANCE);
}
}
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265LaxSpec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265LaxSpec.java
index 0684f14cf..2a37b1c57 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265LaxSpec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265LaxSpec.java
@@ -43,12 +43,12 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
public class RFC6265LaxSpec extends RFC6265CookieSpecBase {
public RFC6265LaxSpec() {
- super(new BasicPathHandler(),
- new BasicDomainHandler(),
- new LaxMaxAgeHandler(),
- new BasicSecureHandler(),
- new BasicHttpOnlyHandler(),
- new LaxExpiresHandler());
+ super(BasicPathHandler.INSTANCE,
+ BasicDomainHandler.INSTANCE,
+ LaxMaxAgeHandler.INSTANCE,
+ BasicSecureHandler.INSTANCE,
+ BasicHttpOnlyHandler.INSTANCE,
+ LaxExpiresHandler.INSTANCE);
}
RFC6265LaxSpec(final CommonCookieAttributeHandler... handlers) {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265StrictSpec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265StrictSpec.java
index b155ba993..1f9baee30 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265StrictSpec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/RFC6265StrictSpec.java
@@ -43,11 +43,11 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
public class RFC6265StrictSpec extends RFC6265CookieSpecBase {
public RFC6265StrictSpec() {
- super(new BasicPathHandler(),
- new BasicDomainHandler(),
- new BasicMaxAgeHandler(),
- new BasicSecureHandler(),
- new BasicHttpOnlyHandler(),
+ super(BasicPathHandler.INSTANCE,
+ BasicDomainHandler.INSTANCE,
+ BasicMaxAgeHandler.INSTANCE,
+ BasicSecureHandler.INSTANCE,
+ BasicHttpOnlyHandler.INSTANCE,
new BasicExpiresHandler(DateUtils.STANDARD_PATTERNS));
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java
index f891e6957..15b197d72 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/BasicRouteDirector.java
@@ -41,6 +41,13 @@ import org.apache.hc.core5.util.Args;
@Contract(threading = ThreadingBehavior.STATELESS)
public class BasicRouteDirector implements HttpRouteDirector {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final BasicRouteDirector INSTANCE = new BasicRouteDirector();
+
/**
* Provides the next step.
*
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java
index 68e9ba6b0..39d67977c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java
@@ -66,6 +66,13 @@ import org.slf4j.LoggerFactory;
@Contract(threading = ThreadingBehavior.STATELESS)
public class RequestAddCookies implements HttpRequestInterceptor {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final RequestAddCookies INSTANCE = new RequestAddCookies();
+
private static final Logger LOG = LoggerFactory.getLogger(RequestAddCookies.class);
public RequestAddCookies() {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestDefaultHeaders.java b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestDefaultHeaders.java
index 6d31b24c5..6293580a9 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestDefaultHeaders.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestDefaultHeaders.java
@@ -49,6 +49,13 @@ import org.apache.hc.core5.util.Args;
@Contract(threading = ThreadingBehavior.STATELESS)
public class RequestDefaultHeaders implements HttpRequestInterceptor {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final RequestDefaultHeaders INSTANCE = new RequestDefaultHeaders();
+
private final Collection<? extends Header> defaultHeaders;
/**
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseProcessCookies.java b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseProcessCookies.java
index 6c02dd7e8..fbfd9c470 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseProcessCookies.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseProcessCookies.java
@@ -58,6 +58,13 @@ import org.slf4j.LoggerFactory;
@Contract(threading = ThreadingBehavior.STATELESS)
public class ResponseProcessCookies implements HttpResponseInterceptor {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final ResponseProcessCookies INSTANCE = new ResponseProcessCookies();
+
private static final Logger LOG = LoggerFactory.getLogger(ResponseProcessCookies.class);
public ResponseProcessCookies() {
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixListParser.java b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixListParser.java
index e943f1fe8..e2f228647 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixListParser.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixListParser.java
@@ -44,6 +44,13 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
@Contract(threading = ThreadingBehavior.STATELESS)
public final class PublicSuffixListParser {
+ /**
+ * Singleton instance.
+ *
+ * @since 5.2
+ */
+ public static final PublicSuffixListParser INSTANCE = new PublicSuffixListParser();
+
public PublicSuffixListParser() {
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcherLoader.java b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcherLoader.java
index 0e8f2dcda..2024a68c3 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcherLoader.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcherLoader.java
@@ -53,7 +53,7 @@ public final class PublicSuffixMatcherLoader {
private static final Logger LOG = LoggerFactory.getLogger(PublicSuffixMatcherLoader.class);
private static PublicSuffixMatcher load(final InputStream in) throws IOException {
- final List<PublicSuffixList> lists = new PublicSuffixListParser().parseByType(
+ final List<PublicSuffixList> lists = PublicSuffixListParser.INSTANCE.parseByType(
new InputStreamReader(in, StandardCharsets.UTF_8));
return new PublicSuffixMatcher(lists);
}
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCookieIdentityComparator.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCookieIdentityComparator.java
index cdfe00c3d..a39960bc2 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCookieIdentityComparator.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCookieIdentityComparator.java
@@ -38,7 +38,7 @@ public class TestCookieIdentityComparator {
@Test
public void testCookieIdentityComparasionByName() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
+ final CookieIdentityComparator comparator = CookieIdentityComparator.INSTANCE;
final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
Assertions.assertEquals(0, comparator.compare(c1, c2));
@@ -50,7 +50,7 @@ public class TestCookieIdentityComparator {
@Test
public void testCookieIdentityComparasionByNameAndDomain() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
+ final CookieIdentityComparator comparator = CookieIdentityComparator.INSTANCE;
final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
c1.setDomain("www.domain.com");
final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
@@ -66,7 +66,7 @@ public class TestCookieIdentityComparator {
@Test
public void testCookieIdentityComparasionByNameAndNullDomain() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
+ final CookieIdentityComparator comparator = CookieIdentityComparator.INSTANCE;
final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
c1.setDomain(null);
final BasicClientCookie c2 = new BasicClientCookie("name", "value2");
@@ -82,7 +82,7 @@ public class TestCookieIdentityComparator {
@Test
public void testCookieIdentityComparasionByNameDomainAndPath() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
+ final CookieIdentityComparator comparator = CookieIdentityComparator.INSTANCE;
final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
c1.setDomain("www.domain.com");
c1.setPath("/whatever");
@@ -102,7 +102,7 @@ public class TestCookieIdentityComparator {
@Test
public void testCookieIdentityComparasionByNameDomainAndNullPath() {
- final CookieIdentityComparator comparator = new CookieIdentityComparator();
+ final CookieIdentityComparator comparator = CookieIdentityComparator.INSTANCE;
final BasicClientCookie c1 = new BasicClientCookie("name", "value1");
c1.setDomain("www.domain.com");
c1.setPath("/");
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java
index e5b62cf56..4b8b63993 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieAttribHandlers.java
@@ -45,7 +45,7 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicDomainParse() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
h.parse(cookie, "www.somedomain.com");
Assertions.assertEquals("www.somedomain.com", cookie.getDomain());
}
@@ -53,7 +53,7 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicDomainParseInvalid1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, ""));
}
@@ -61,7 +61,7 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicDomainParseInvalid2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, null));
}
@@ -70,7 +70,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainValidate1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain(".somedomain.com");
h.validate(cookie, origin);
@@ -85,7 +85,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainValidate2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain("somehost");
h.validate(cookie, origin);
@@ -98,7 +98,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainValidate3() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain(".somedomain.com");
h.validate(cookie, origin);
@@ -108,7 +108,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainValidate4() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain(null);
Assertions.assertThrows(MalformedCookieException.class, () -> h.validate(cookie, origin));
@@ -118,7 +118,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainMatch1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain("somedomain.com");
cookie.setAttribute(Cookie.DOMAIN_ATTR, "somedomain.com");
@@ -132,7 +132,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainMatch2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain("somedomain.com");
cookie.setAttribute(Cookie.DOMAIN_ATTR, "somedomain.com");
@@ -149,7 +149,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainMatchOneLetterPrefix() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("a.somedomain.com", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain("somedomain.com");
cookie.setAttribute(Cookie.DOMAIN_ATTR, "somedomain.com");
@@ -160,7 +160,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicDomainMatchMixedCase() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("a.SomeDomain.com", 80, "/", false);
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
cookie.setDomain("somedoMain.Com");
cookie.setAttribute(Cookie.DOMAIN_ATTR, "somedoMain.Com");
@@ -169,7 +169,7 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicDomainInvalidInput() throws Exception {
- final CookieAttributeHandler h = new BasicDomainHandler();
+ final CookieAttributeHandler h = BasicDomainHandler.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () -> h.parse(null, null));
Assertions.assertThrows(NullPointerException.class, () -> h.validate(null, null));
Assertions.assertThrows(NullPointerException.class, () ->
@@ -182,7 +182,7 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicPathParse() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
h.parse(cookie, "stuff");
Assertions.assertEquals("stuff", cookie.getPath());
h.parse(cookie, "");
@@ -195,7 +195,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicPathMatch1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false);
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
cookie.setPath("/stuff");
Assertions.assertTrue(h.match(cookie, origin));
}
@@ -204,7 +204,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicPathMatch2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff/", false);
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
cookie.setPath("/stuff");
Assertions.assertTrue(h.match(cookie, origin));
}
@@ -213,7 +213,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicPathMatch3() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff/more-stuff", false);
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
cookie.setPath("/stuff");
Assertions.assertTrue(h.match(cookie, origin));
}
@@ -222,7 +222,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicPathMatch4() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuffed", false);
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
cookie.setPath("/stuff");
Assertions.assertFalse(h.match(cookie, origin));
}
@@ -231,7 +231,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicPathMatch5() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/otherstuff", false);
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
cookie.setPath("/stuff");
Assertions.assertFalse(h.match(cookie, origin));
}
@@ -240,7 +240,7 @@ public class TestBasicCookieAttribHandlers {
public void testBasicPathMatch6() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false);
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
cookie.setPath("/stuff/");
Assertions.assertTrue(h.match(cookie, origin));
}
@@ -249,13 +249,13 @@ public class TestBasicCookieAttribHandlers {
public void testBasicPathMatch7() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false);
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
Assertions.assertTrue(h.match(cookie, origin));
}
@Test
public void testBasicPathInvalidInput() throws Exception {
- final CookieAttributeHandler h = new BasicPathHandler();
+ final CookieAttributeHandler h = BasicPathHandler.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () -> h.parse(null, null));
Assertions.assertThrows(NullPointerException.class, () -> h.match(null, null));
Assertions.assertThrows(NullPointerException.class, () ->
@@ -265,7 +265,7 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicMaxAgeParse() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicMaxAgeHandler();
+ final CookieAttributeHandler h = BasicMaxAgeHandler.INSTANCE;
h.parse(cookie, "2000");
Assertions.assertNotNull(cookie.getExpiryInstant());
}
@@ -273,21 +273,21 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicMaxAgeParseInvalid() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicMaxAgeHandler();
+ final CookieAttributeHandler h = BasicMaxAgeHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () -> h.parse(cookie, "garbage"));
Assertions.assertThrows(MalformedCookieException.class, () -> h.parse(cookie, null));
}
@Test
public void testBasicMaxAgeInvalidInput() throws Exception {
- final CookieAttributeHandler h = new BasicMaxAgeHandler();
+ final CookieAttributeHandler h = BasicMaxAgeHandler.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () -> h.parse(null, null));
}
@Test
public void testBasicSecureParse() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicSecureHandler();
+ final CookieAttributeHandler h = BasicSecureHandler.INSTANCE;
h.parse(cookie, "whatever");
Assertions.assertTrue(cookie.isSecure());
h.parse(cookie, null);
@@ -297,7 +297,7 @@ public class TestBasicCookieAttribHandlers {
@Test
public void testBasicSecureMatch() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new BasicSecureHandler();
+ final CookieAttributeHandler h = BasicSecureHandler.INSTANCE;
final CookieOrigin origin1 = new CookieOrigin("somehost", 80, "/stuff", false);
cookie.setSecure(false);
@@ -352,7 +352,7 @@ public class TestBasicCookieAttribHandlers {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final PublicSuffixMatcher matcher = new PublicSuffixMatcher(DomainType.ICANN, Arrays.asList("co.uk", "com"), null);
- final PublicSuffixDomainFilter h = new PublicSuffixDomainFilter(new BasicDomainHandler(), matcher);
+ final PublicSuffixDomainFilter h = new PublicSuffixDomainFilter(BasicDomainHandler.INSTANCE, matcher);
cookie.setDomain(".co.uk");
cookie.setAttribute(Cookie.DOMAIN_ATTR, ".co.uk");
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
index 21335129d..47aa9a825 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
@@ -41,7 +41,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseMaxAge() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxMaxAgeHandler();
+ final CookieAttributeHandler h = LaxMaxAgeHandler.INSTANCE;
h.parse(cookie, "2000");
Assertions.assertNotNull(cookie.getExpiryInstant());
}
@@ -49,7 +49,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseMaxNegative() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxMaxAgeHandler();
+ final CookieAttributeHandler h = LaxMaxAgeHandler.INSTANCE;
h.parse(cookie, "-2000");
Assertions.assertNotNull(cookie.getExpiryInstant());
}
@@ -57,7 +57,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseMaxZero() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxMaxAgeHandler();
+ final CookieAttributeHandler h = LaxMaxAgeHandler.INSTANCE;
h.parse(cookie, "0000");
Assertions.assertNotNull(cookie.getExpiryInstant());
}
@@ -65,7 +65,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testBasicMaxAgeParseEmpty() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxMaxAgeHandler();
+ final CookieAttributeHandler h = LaxMaxAgeHandler.INSTANCE;
h.parse(cookie, " ");
Assertions.assertNull(cookie.getExpiryInstant());
}
@@ -73,21 +73,21 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testBasicMaxAgeParseInvalid() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxMaxAgeHandler();
+ final CookieAttributeHandler h = LaxMaxAgeHandler.INSTANCE;
h.parse(cookie, "garbage");
Assertions.assertNull(cookie.getExpiryInstant());
}
@Test
public void testBasicMaxAgeInvalidInput() throws Exception {
- final CookieAttributeHandler h = new LaxMaxAgeHandler();
+ final CookieAttributeHandler h = LaxMaxAgeHandler.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () -> h.parse(null, "stuff"));
}
@Test
public void testExpiryGarbage() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, ";;blah,blah;yada "));
}
@@ -95,7 +95,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiry() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "1:0:12 8-jan-2012");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -113,7 +113,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInstant() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "1:0:12 8-jan-2012");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -131,7 +131,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidTime0() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, null);
Assertions.assertNull(cookie.getExpiryInstant());
}
@@ -139,7 +139,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidTime1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "1:0:122 8 dec 1980"));
}
@@ -147,7 +147,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidTime2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "24:00:00 8 dec 1980"));
}
@@ -155,7 +155,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidTime3() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "23:60:00 8 dec 1980"));
}
@@ -163,7 +163,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidTime4() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "23:00:60 8 dec 1980"));
}
@@ -171,7 +171,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyTime() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "1:59:00blah; 8-feb-2000");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -189,7 +189,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyTimeInstant() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "1:59:00blah; 8-feb-2000");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -207,7 +207,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidDayOfMonth1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "12:00:00 888 mar 1880"));
}
@@ -215,7 +215,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidDayOfMonth2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "12:00:00 0 mar 1880"));
}
@@ -223,7 +223,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidDayOfMonth3() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "12:00:00 32 mar 1880"));
}
@@ -231,7 +231,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyDayOfMonth() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "12:00:00 8blah;mar;1880");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -249,7 +249,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyDayOfMonthInstant() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "12:00:00 8blah;mar;1880");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -267,7 +267,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidMonth() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "1:00:00 8 dek 80"));
}
@@ -275,7 +275,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyMonth() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "23:59:59; 1-ApriLLLLL-2008");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -293,7 +293,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyMonthInstant() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "23:59:59; 1-ApriLLLLL-2008");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -311,7 +311,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidYearTooShort() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "1:00:00 8 dec 8"));
}
@@ -319,7 +319,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidYearTooLong() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "1:00:00 8 dec 88888"));
}
@@ -327,7 +327,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryInvalidYearTooLongAgo() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
Assertions.assertThrows(MalformedCookieException.class, () ->
h.parse(cookie, "1:00:00 8 dec 1600"));
}
@@ -335,7 +335,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyYear() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "23:59:59; 1-Apr-2008blah");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -353,7 +353,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryFunnyYearInstant() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "23:59:59; 1-Apr-2008blah");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -371,7 +371,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryYearTwoDigit1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "23:59:59; 1-Apr-70");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -383,7 +383,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryYearTwoDigit2() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "23:59:59; 1-Apr-99");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
@@ -395,7 +395,7 @@ public class TestLaxCookieAttribHandlers {
@Test
public void testParseExpiryYearTwoDigit3() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
- final CookieAttributeHandler h = new LaxExpiresHandler();
+ final CookieAttributeHandler h = LaxExpiresHandler.INSTANCE;
h.parse(cookie, "23:59:59; 1-Apr-00");
final LocalDateTime expiryDate = DateUtils.toUTC(cookie.getExpiryInstant());
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestPublicSuffixListParser.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestPublicSuffixListParser.java
index 5ae29e888..c8e2f69e4 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestPublicSuffixListParser.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestPublicSuffixListParser.java
@@ -53,13 +53,13 @@ public class TestPublicSuffixListParser {
Assertions.assertNotNull(in);
final PublicSuffixList suffixList;
try {
- final PublicSuffixListParser parser = new PublicSuffixListParser();
+ final PublicSuffixListParser parser = PublicSuffixListParser.INSTANCE;
suffixList = parser.parse(new InputStreamReader(in, StandardCharsets.UTF_8));
} finally {
in.close();
}
final PublicSuffixMatcher matcher = new PublicSuffixMatcher(suffixList.getRules(), suffixList.getExceptions());
- this.filter = new PublicSuffixDomainFilter(new BasicDomainHandler(), matcher);
+ this.filter = new PublicSuffixDomainFilter(BasicDomainHandler.INSTANCE, matcher);
}
@Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java
index b324c94f5..1890d281b 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteDirector.java
@@ -83,7 +83,7 @@ public class TestRouteDirector {
@Test
public void testIllegal() {
- final HttpRouteDirector rowdy = new BasicRouteDirector();
+ final HttpRouteDirector rowdy = BasicRouteDirector.INSTANCE;
final HttpRoute route = new HttpRoute(TARGET1);
Assertions.assertThrows(NullPointerException.class, () ->
rowdy.nextStep(null, route));
@@ -92,7 +92,7 @@ public class TestRouteDirector {
@Test
public void testDirect() {
- final HttpRouteDirector rowdy = new BasicRouteDirector();
+ final HttpRouteDirector rowdy = BasicRouteDirector.INSTANCE;
final HttpRoute route1 = new HttpRoute(TARGET1);
final HttpRoute route2 = new HttpRoute(TARGET2);
final HttpRoute route1p1 = new HttpRoute(TARGET1, null, PROXY1, false);
@@ -119,7 +119,7 @@ public class TestRouteDirector {
@Test
public void testProxy() {
- final HttpRouteDirector rowdy = new BasicRouteDirector();
+ final HttpRouteDirector rowdy = BasicRouteDirector.INSTANCE;
final HttpRoute route1p1 = new HttpRoute(TARGET1, null, PROXY1, false);
final HttpRoute route1p2 = new HttpRoute(TARGET1, null, PROXY2, false);
final HttpRoute route2p1 = new HttpRoute(TARGET2, null, PROXY1, false);
@@ -160,7 +160,7 @@ public class TestRouteDirector {
final HttpHost[] chainB = { PROXY1, PROXY2 };
final HttpHost[] chainC = { PROXY2, PROXY1 };
- final HttpRouteDirector rowdy = new BasicRouteDirector();
+ final HttpRouteDirector rowdy = BasicRouteDirector.INSTANCE;
final HttpRoute route1cA = new HttpRoute(TARGET1, null, chainA, false,
TunnelType.PLAIN, LayerType.PLAIN);
final HttpRoute route1cB = new HttpRoute(TARGET1, null, chainB, false,
@@ -203,7 +203,7 @@ public class TestRouteDirector {
@Test
public void testLocalDirect() {
- final HttpRouteDirector rowdy = new BasicRouteDirector();
+ final HttpRouteDirector rowdy = BasicRouteDirector.INSTANCE;
final HttpRoute route1l41 = new HttpRoute(TARGET1, LOCAL41, false);
final HttpRoute route1l42 = new HttpRoute(TARGET1, LOCAL42, false);
final HttpRoute route1l61 = new HttpRoute(TARGET1, LOCAL61, false);
@@ -257,7 +257,7 @@ public class TestRouteDirector {
@Test
public void testDirectSecure() {
- final HttpRouteDirector rowdy = new BasicRouteDirector();
+ final HttpRouteDirector rowdy = BasicRouteDirector.INSTANCE;
final HttpRoute route1u = new HttpRoute(TARGET1, null, false);
final HttpRoute route1s = new HttpRoute(TARGET1, null, true);
final HttpRoute route1p1u = new HttpRoute(TARGET1, null, PROXY1, false);
@@ -289,7 +289,7 @@ public class TestRouteDirector {
@Test
public void testProxyTLS() {
- final HttpRouteDirector rowdy = new BasicRouteDirector();
+ final HttpRouteDirector rowdy = BasicRouteDirector.INSTANCE;
final HttpRoute route1 = new HttpRoute
(TARGET1, null, PROXY1, false,
TunnelType.PLAIN, LayerType.PLAIN);
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteTracker.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteTracker.java
index 210eb25c9..ad77953b6 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteTracker.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/routing/TestRouteTracker.java
@@ -181,7 +181,7 @@ public class TestRouteTracker {
@Test
public void testDirectRoutes() {
- final HttpRouteDirector rd = new BasicRouteDirector();
+ final HttpRouteDirector rd = BasicRouteDirector.INSTANCE;
HttpRoute r = new HttpRoute(TARGET1, LOCAL41, false);
RouteTracker rt = new RouteTracker(r);
boolean complete = checkVia(rt, r, rd, 2);
@@ -196,7 +196,7 @@ public class TestRouteTracker {
@Test
public void testProxyRoutes() {
- final HttpRouteDirector rd = new BasicRouteDirector();
+ final HttpRouteDirector rd = BasicRouteDirector.INSTANCE;
HttpRoute r = new HttpRoute(TARGET2, null, PROXY1, false);
RouteTracker rt = new RouteTracker(r);
boolean complete = checkVia(rt, r, rd, 2);
@@ -226,7 +226,7 @@ public class TestRouteTracker {
@Test
public void testProxyChainRoutes() {
- final HttpRouteDirector rd = new BasicRouteDirector();
+ final HttpRouteDirector rd = BasicRouteDirector.INSTANCE;
HttpHost[] proxies = { PROXY1, PROXY2 };
HttpRoute r = new HttpRoute(TARGET2, LOCAL42, proxies, false,
TunnelType.PLAIN, LayerType.PLAIN);
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java
index bc1d52bcf..5b7f495e4 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java
@@ -87,7 +87,7 @@ public class TestRequestAddCookies {
@Test
public void testRequestParameterCheck() throws Exception {
final HttpClientContext context = HttpClientContext.create();
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () ->
interceptor.process(null, null, context));
}
@@ -95,7 +95,7 @@ public class TestRequestAddCookies {
@Test
public void testContextParameterCheck() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () ->
interceptor.process(request, null, null));
}
@@ -111,7 +111,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers = request.getHeaders("Cookie");
@@ -138,7 +138,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers = request.getHeaders("Cookie");
@@ -157,7 +157,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, null);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers = request.getHeaders("Cookie");
@@ -176,7 +176,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, null);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers = request.getHeaders("Cookie");
@@ -193,7 +193,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers = request.getHeaders("Cookie");
@@ -215,7 +215,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final CookieSpec cookieSpec = context.getCookieSpec();
@@ -238,7 +238,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
}
@@ -254,7 +254,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final CookieOrigin cookieOrigin = context.getCookieOrigin();
@@ -278,7 +278,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final CookieOrigin cookieOrigin = context.getCookieOrigin();
@@ -303,7 +303,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final CookieOrigin cookieOrigin = context.getCookieOrigin();
@@ -338,7 +338,7 @@ public class TestRequestAddCookies {
// Make sure the third cookie expires
Thread.sleep(200);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers = request.getHeaders("Cookie");
@@ -366,7 +366,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers = request.getHeaders("Cookie");
@@ -401,7 +401,7 @@ public class TestRequestAddCookies {
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
- final HttpRequestInterceptor interceptor = new RequestAddCookies();
+ final HttpRequestInterceptor interceptor = RequestAddCookies.INSTANCE;
interceptor.process(request, null, context);
final Header[] headers1 = request.getHeaders("Cookie");
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java
index fc23dd5a6..d3763887d 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestDefaultHeaders.java
@@ -44,7 +44,7 @@ public class TestRequestDefaultHeaders {
@Test
public void testRequestParameterCheck() throws Exception {
final HttpContext context = new BasicHttpContext();
- final HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
+ final HttpRequestInterceptor interceptor = RequestDefaultHeaders.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () ->
interceptor.process(null, null, context));
}
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java
index f9f65dd0d..e8eb8306e 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseProcessCookies.java
@@ -57,7 +57,7 @@ public class TestResponseProcessCookies {
@Test
public void testResponseParameterCheck() throws Exception {
final HttpClientContext context = HttpClientContext.create();
- final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
+ final HttpResponseInterceptor interceptor = ResponseProcessCookies.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () ->
interceptor.process(null, null, context));
}
@@ -65,7 +65,7 @@ public class TestResponseProcessCookies {
@Test
public void testContextParameterCheck() throws Exception {
final HttpResponse response = new BasicHttpResponse(200, "OK");
- final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
+ final HttpResponseInterceptor interceptor = ResponseProcessCookies.INSTANCE;
Assertions.assertThrows(NullPointerException.class, () ->
interceptor.process(response, null, null));
}
@@ -80,7 +80,7 @@ public class TestResponseProcessCookies {
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
- final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
+ final HttpResponseInterceptor interceptor = ResponseProcessCookies.INSTANCE;
interceptor.process(response, null, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
@@ -103,7 +103,7 @@ public class TestResponseProcessCookies {
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
- final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
+ final HttpResponseInterceptor interceptor = ResponseProcessCookies.INSTANCE;
interceptor.process(response, null, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
@@ -121,7 +121,7 @@ public class TestResponseProcessCookies {
context.setAttribute(HttpClientContext.COOKIE_SPEC, null);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
- final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
+ final HttpResponseInterceptor interceptor = ResponseProcessCookies.INSTANCE;
interceptor.process(response, null, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
@@ -139,7 +139,7 @@ public class TestResponseProcessCookies {
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, null);
- final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
+ final HttpResponseInterceptor interceptor = ResponseProcessCookies.INSTANCE;
interceptor.process(response, null, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixListParser.java b/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixListParser.java
index 46d6b5240..7f34d347b 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixListParser.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixListParser.java
@@ -46,7 +46,7 @@ public class TestPublicSuffixListParser {
Assertions.assertNotNull(in);
final PublicSuffixList suffixList;
try {
- final PublicSuffixListParser parser = new PublicSuffixListParser();
+ final PublicSuffixListParser parser = PublicSuffixListParser.INSTANCE;
suffixList = parser.parse(new InputStreamReader(in, StandardCharsets.UTF_8));
} finally {
in.close();
@@ -63,7 +63,7 @@ public class TestPublicSuffixListParser {
Assertions.assertNotNull(in);
final List<PublicSuffixList> suffixLists;
try {
- final PublicSuffixListParser parser = new PublicSuffixListParser();
+ final PublicSuffixListParser parser = PublicSuffixListParser.INSTANCE;
suffixLists = parser.parseByType(new InputStreamReader(in, StandardCharsets.UTF_8));
} finally {
in.close();
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java b/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java
index 6f4b7ae0d..03d5b5c86 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java
@@ -47,7 +47,7 @@ public class TestPublicSuffixMatcher {
final ClassLoader classLoader = getClass().getClassLoader();
final InputStream in = classLoader.getResourceAsStream(SOURCE_FILE);
Assertions.assertNotNull(in);
- final List<PublicSuffixList> lists = new PublicSuffixListParser().parseByType(
+ final List<PublicSuffixList> lists = PublicSuffixListParser.INSTANCE.parseByType(
new InputStreamReader(in, StandardCharsets.UTF_8));
matcher = new PublicSuffixMatcher(lists);
}
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java b/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java
index c2d460c3d..67ae939d3 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java
@@ -66,7 +66,7 @@ public class TestDefaultHostnameVerifier {
final ClassLoader classLoader = getClass().getClassLoader();
final InputStream in = classLoader.getResourceAsStream(PUBLIC_SUFFIX_MATCHER_SOURCE_FILE);
Assertions.assertNotNull(in);
- final List<PublicSuffixList> lists = new PublicSuffixListParser().parseByType(
+ final List<PublicSuffixList> lists = PublicSuffixListParser.INSTANCE.parseByType(
new InputStreamReader(in, StandardCharsets.UTF_8));
publicSuffixMatcher = new PublicSuffixMatcher(lists);