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 2021/03/11 21:55:43 UTC
[httpcomponents-client] 02/05: Deprecated message copiers in favor
of generic message 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-client.git
commit 3de88293fe665e67df1854152faaaa10d6b23ce3
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Mar 8 22:26:30 2021 +0100
Deprecated message copiers in favor of generic message builders
---
.../client5/http/impl/cache/AsyncCachingExec.java | 25 ++++++++++++-----
.../hc/client5/http/impl/cache/CachingExec.java | 12 +++++++--
.../http/impl/cache/ConditionalRequestBuilder.java | 15 +++++------
.../http/impl/cache/AbstractProtocolTest.java | 8 +++---
.../http/impl/cache/TestCachingExecChain.java | 12 +++++----
.../impl/cache/TestConditionalRequestBuilder.java | 31 +++++++++++-----------
.../http/impl/cache/TestProtocolDeviations.java | 6 ++---
.../impl/cache/TestRequestProtocolCompliance.java | 18 ++++++-------
.../impl/cache/TestResponseProtocolCompliance.java | 4 +--
.../apache/hc/client5/http/impl/MessageCopier.java | 3 +++
.../apache/hc/client5/http/impl/RequestCopier.java | 3 +++
.../http/impl/async/AsyncHttpRequestRetryExec.java | 4 +--
.../async/InternalAbstractHttpAsyncClient.java | 4 +--
.../http/impl/classic/ClassicRequestCopier.java | 3 +++
.../http/impl/classic/HttpRequestRetryExec.java | 7 ++---
.../http/impl/classic/InternalHttpClient.java | 3 ++-
.../impl/classic/TestHttpRequestRetryExec.java | 7 ++---
17 files changed, 100 insertions(+), 65 deletions(-)
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
index 2ccae57..d12215a 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
@@ -49,7 +49,6 @@ import org.apache.hc.client5.http.cache.HttpCacheEntry;
import org.apache.hc.client5.http.cache.ResourceFactory;
import org.apache.hc.client5.http.cache.ResourceIOException;
import org.apache.hc.client5.http.impl.ExecSupport;
-import org.apache.hc.client5.http.impl.RequestCopier;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.schedule.SchedulingStrategy;
import org.apache.hc.client5.http.utils.DateUtils;
@@ -58,6 +57,7 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.concurrent.CancellableDependency;
import org.apache.hc.core5.concurrent.ComplexFuture;
import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.function.Factory;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
@@ -72,6 +72,7 @@ import org.apache.hc.core5.http.nio.AsyncDataConsumer;
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
import org.apache.hc.core5.http.nio.CapacityChannel;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
+import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.apache.hc.core5.net.URIAuthority;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.ByteArrayBuffer;
@@ -101,7 +102,14 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
super(config);
this.responseCache = Args.notNull(cache, "Response cache");
this.cacheRevalidator = cacheRevalidator;
- this.conditionalRequestBuilder = new ConditionalRequestBuilder<>(RequestCopier.INSTANCE);
+ this.conditionalRequestBuilder = new ConditionalRequestBuilder<>(new Factory<HttpRequest, HttpRequest>() {
+
+ @Override
+ public HttpRequest create(final HttpRequest request) {
+ return BasicRequestBuilder.copy(request).build();
+ }
+
+ });
}
AsyncCachingExec(
@@ -695,7 +703,9 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
final AsyncExecCallback asyncExecCallback,
final HttpCacheEntry cacheEntry) {
final Date requestDate = getCurrentDate();
- final HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(scope.originalRequest, cacheEntry);
+ final HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(
+ BasicRequestBuilder.copy(scope.originalRequest).build(),
+ cacheEntry);
chainProceed(conditionalRequest, entityProducer, scope, chain, new AsyncExecCallback() {
final AtomicReference<AsyncExecCallback> callbackRef = new AtomicReference<>();
@@ -795,7 +805,7 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
&& (entityProducer == null || entityProducer.isRepeatable())) {
final HttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(
- scope.originalRequest);
+ BasicRequestBuilder.copy(scope.originalRequest).build());
callback1 = new AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
@@ -940,7 +950,9 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
final AsyncExecCallback asyncExecCallback,
final Map<String, Variant> variants) {
final CancellableDependency operation = scope.cancellableDependency;
- final HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants(request, variants);
+ final HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants(
+ BasicRequestBuilder.copy(request).build(),
+ variants);
final Date requestDate = getCurrentDate();
chainProceed(conditionalRequest, entityProducer, scope, chain, new AsyncExecCallback() {
@@ -1045,7 +1057,8 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
});
} else {
if (revalidationResponseIsTooOld(backendResponse, matchingVariant.getEntry())) {
- final HttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(request);
+ final HttpRequest unconditional = conditionalRequestBuilder.buildUnconditionalRequest(
+ BasicRequestBuilder.copy(request).build());
scope.clientContext.setAttribute(HttpCoreContext.HTTP_REQUEST, unconditional);
callback = new AsyncExecCallbackWrapper(asyncExecCallback, new Runnable() {
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
index 80ea417..fa702e0 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
@@ -45,10 +45,10 @@ import org.apache.hc.client5.http.cache.ResourceIOException;
import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecChainHandler;
import org.apache.hc.client5.http.impl.ExecSupport;
-import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.schedule.SchedulingStrategy;
import org.apache.hc.client5.http.utils.DateUtils;
+import org.apache.hc.core5.function.Factory;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
@@ -62,6 +62,7 @@ import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.net.URIAuthority;
@@ -110,7 +111,14 @@ class CachingExec extends CachingExecBase implements ExecChainHandler {
super(config);
this.responseCache = Args.notNull(cache, "Response cache");
this.cacheRevalidator = cacheRevalidator;
- this.conditionalRequestBuilder = new ConditionalRequestBuilder<>(ClassicRequestCopier.INSTANCE);
+ this.conditionalRequestBuilder = new ConditionalRequestBuilder<>(new Factory<ClassicHttpRequest, ClassicHttpRequest>() {
+
+ @Override
+ public ClassicHttpRequest create(final ClassicHttpRequest classicHttpRequest) {
+ return ClassicRequestBuilder.copy(classicHttpRequest).build();
+ }
+
+ });
}
CachingExec(
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java
index c539375..51070eb 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java
@@ -31,7 +31,7 @@ import java.util.Map;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
-import org.apache.hc.client5.http.impl.MessageCopier;
+import org.apache.hc.core5.function.Factory;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpRequest;
@@ -39,9 +39,9 @@ import org.apache.hc.core5.http.message.MessageSupport;
class ConditionalRequestBuilder<T extends HttpRequest> {
- private final MessageCopier<T> messageCopier;
+ private final Factory<T, T> messageCopier;
- ConditionalRequestBuilder(final MessageCopier<T> messageCopier) {
+ ConditionalRequestBuilder(final Factory<T, T> messageCopier) {
this.messageCopier = messageCopier;
}
@@ -56,8 +56,8 @@ class ConditionalRequestBuilder<T extends HttpRequest> {
* @return the wrapped request
*/
public T buildConditionalRequest(final T request, final HttpCacheEntry cacheEntry) {
- final T newRequest = messageCopier.copy(request);
- newRequest.setHeaders(request.getHeaders());
+ final T newRequest = messageCopier.create(request);
+
final Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
if (eTag != null) {
newRequest.setHeader(HeaderConstants.IF_NONE_MATCH, eTag.getValue());
@@ -95,8 +95,7 @@ class ConditionalRequestBuilder<T extends HttpRequest> {
* @return the wrapped request
*/
public T buildConditionalRequestFromVariants(final T request, final Map<String, Variant> variants) {
- final T newRequest = messageCopier.copy(request);
- newRequest.setHeaders(request.getHeaders());
+ final T newRequest = messageCopier.create(request);
// we do not support partial content so all etags are used
final StringBuilder etags = new StringBuilder();
@@ -124,7 +123,7 @@ class ConditionalRequestBuilder<T extends HttpRequest> {
* @return an unconditional validation request
*/
public T buildUnconditionalRequest(final T request) {
- final T newRequest = messageCopier.copy(request);
+ final T newRequest = messageCopier.create(request);
newRequest.addHeader(HeaderConstants.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE);
newRequest.addHeader(HeaderConstants.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE);
newRequest.removeHeaders(HeaderConstants.IF_RANGE);
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
index 8438a32..8d83f7f 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
@@ -33,7 +33,6 @@ import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecChainHandler;
import org.apache.hc.client5.http.classic.ExecRuntime;
-import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
@@ -42,6 +41,7 @@ import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.easymock.EasyMock;
import org.easymock.IExpectationSetters;
@@ -107,8 +107,10 @@ public abstract class AbstractProtocolTest {
}
public ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException, HttpException {
- return impl.execute(ClassicRequestCopier.INSTANCE.copy(request), new ExecChain.Scope(
- "test", route, request, mockExecRuntime, context), mockExecChain);
+ return impl.execute(
+ ClassicRequestBuilder.copy(request).build(),
+ new ExecChain.Scope("test", route, request, mockExecRuntime, context),
+ mockExecChain);
}
protected ExecChainHandler createCachingExecChain(final HttpCache cache, final CacheConfig config) {
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
index edbe9b8..842d200 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java
@@ -27,13 +27,13 @@
package org.apache.hc.client5.http.impl.cache;
import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.same;
-import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.same;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -59,7 +59,6 @@ import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecRuntime;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpOptions;
-import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -74,6 +73,7 @@ import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.InputStreamEntity;
+import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
import org.apache.hc.core5.http.message.BasicHeader;
@@ -165,8 +165,10 @@ public abstract class TestCachingExecChain {
public abstract CachingExec createCachingExecChain(HttpCache cache, CacheConfig config);
protected ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException, HttpException {
- return impl.execute(ClassicRequestCopier.INSTANCE.copy(request), new ExecChain.Scope(
- "test", route, request, mockEndpoint, context), mockExecChain);
+ return impl.execute(
+ ClassicRequestBuilder.copy(request).build(),
+ new ExecChain.Scope("test", route, request, mockEndpoint, context),
+ mockExecChain);
}
public static ClassicHttpRequest eqRequest(final ClassicHttpRequest in) {
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
index 8f65455..186b886 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
@@ -33,14 +33,15 @@ import java.util.Map;
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
-import org.apache.hc.client5.http.impl.RequestCopier;
import org.apache.hc.client5.http.utils.DateUtils;
+import org.apache.hc.core5.function.Factory;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElement;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.http.message.BasicHttpRequest;
import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -52,7 +53,14 @@ public class TestConditionalRequestBuilder {
@Before
public void setUp() throws Exception {
- impl = new ConditionalRequestBuilder<>(RequestCopier.INSTANCE);
+ impl = new ConditionalRequestBuilder<>(new Factory<HttpRequest, HttpRequest>() {
+
+ @Override
+ public HttpRequest create(final HttpRequest request) {
+ return BasicRequestBuilder.copy(request).build();
+ }
+
+ });
request = new BasicHttpRequest("GET", "/");
}
@@ -64,16 +72,13 @@ public class TestConditionalRequestBuilder {
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
basicRequest.addHeader("Accept-Encoding", "gzip");
- final HttpRequest requestWrapper = RequestCopier.INSTANCE.copy(basicRequest);
final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(new Date())),
new BasicHeader("Last-Modified", lastModified) };
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
- final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
-
- Assert.assertNotSame(basicRequest, newRequest);
+ final HttpRequest newRequest = impl.buildConditionalRequest(basicRequest, cacheEntry);
Assert.assertEquals(theMethod, newRequest.getMethod());
Assert.assertEquals(theUri, newRequest.getRequestUri());
@@ -100,9 +105,8 @@ public class TestConditionalRequestBuilder {
new BasicHeader("ETag", etag)
};
final HttpRequest basicRequest = new BasicHttpRequest("GET", "/");
- final HttpRequest requestWrapper = RequestCopier.INSTANCE.copy(basicRequest);
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
- final HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
+ final HttpRequest result = impl.buildConditionalRequest(basicRequest, cacheEntry);
Assert.assertEquals(lmDate,
result.getFirstHeader("If-Modified-Since").getValue());
Assert.assertEquals(etag,
@@ -117,7 +121,6 @@ public class TestConditionalRequestBuilder {
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
basicRequest.addHeader("Accept-Encoding", "gzip");
- final HttpRequest requestWrapper = RequestCopier.INSTANCE.copy(basicRequest);
final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(new Date())),
@@ -126,9 +129,7 @@ public class TestConditionalRequestBuilder {
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
- final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
-
- Assert.assertNotSame(basicRequest, newRequest);
+ final HttpRequest newRequest = impl.buildConditionalRequest(basicRequest, cacheEntry);
Assert.assertEquals(theMethod, newRequest.getMethod());
Assert.assertEquals(theUri, newRequest.getRequestUri());
@@ -145,7 +146,6 @@ public class TestConditionalRequestBuilder {
@Test
public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception {
final HttpRequest basicRequest = new BasicHttpRequest("GET","/");
- final HttpRequest requestWrapper = RequestCopier.INSTANCE.copy(basicRequest);
final Date now = new Date();
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -157,7 +157,7 @@ public class TestConditionalRequestBuilder {
new BasicHeader("Cache-Control","max-age=5, must-revalidate") };
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(elevenSecondsAgo, nineSecondsAgo, cacheEntryHeaders);
- final HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
+ final HttpRequest result = impl.buildConditionalRequest(basicRequest, cacheEntry);
boolean foundMaxAge0 = false;
@@ -174,7 +174,6 @@ public class TestConditionalRequestBuilder {
@Test
public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception {
final HttpRequest basicRequest = new BasicHttpRequest("GET", "/");
- final HttpRequest requestWrapper = RequestCopier.INSTANCE.copy(basicRequest);
final Date now = new Date();
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -186,7 +185,7 @@ public class TestConditionalRequestBuilder {
new BasicHeader("Cache-Control","max-age=5, proxy-revalidate") };
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(elevenSecondsAgo, nineSecondsAgo, cacheEntryHeaders);
- final HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
+ final HttpRequest result = impl.buildConditionalRequest(basicRequest, cacheEntry);
boolean foundMaxAge0 = false;
final Iterator<HeaderElement> it = MessageSupport.iterate(result, HeaderConstants.CACHE_CONTROL);
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
index cd8078d..0d16bc4 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java
@@ -36,7 +36,6 @@ import org.apache.hc.client5.http.cache.HttpCacheContext;
import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecChainHandler;
import org.apache.hc.client5.http.classic.ExecRuntime;
-import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
@@ -115,8 +114,9 @@ public class TestProtocolDeviations {
}
private ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException, HttpException {
- return impl.execute(ClassicRequestCopier.INSTANCE.copy(request), new ExecChain.Scope(
- "test", route, request, mockEndpoint, context), mockExecChain);
+ return impl.execute(request,
+ new ExecChain.Scope("test", route, request, mockEndpoint, context),
+ mockExecChain);
}
protected ExecChainHandler createCachingExecChain(final HttpCache cache, final CacheConfig config) {
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java
index 7ce3a75..32da1cd 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java
@@ -31,11 +31,11 @@ import static org.junit.Assert.assertTrue;
import java.util.Collections;
-import org.apache.hc.client5.http.impl.RequestCopier;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.message.BasicHttpRequest;
+import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.junit.Before;
import org.junit.Test;
@@ -81,7 +81,7 @@ public class TestRequestProtocolCompliance {
@Test
public void doesNotModifyACompliantRequest() throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertTrue(HttpTestUtils.equivalent(req, wrapper));
}
@@ -90,7 +90,7 @@ public class TestRequestProtocolCompliance {
public void upgrades1_0RequestTo1_1() throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setVersion(HttpVersion.HTTP_1_0);
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertEquals(HttpVersion.HTTP_1_1, wrapper.getVersion());
}
@@ -99,7 +99,7 @@ public class TestRequestProtocolCompliance {
public void downgrades1_2RequestTo1_1() throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setVersion(new ProtocolVersion("HTTP", 1, 2));
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertEquals(HttpVersion.HTTP_1_1, wrapper.getVersion());
}
@@ -109,7 +109,7 @@ public class TestRequestProtocolCompliance {
throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setHeader("Cache-Control", "no-cache, min-fresh=10");
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -120,7 +120,7 @@ public class TestRequestProtocolCompliance {
throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setHeader("Cache-Control", "no-cache, max-stale=10");
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -131,7 +131,7 @@ public class TestRequestProtocolCompliance {
throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setHeader("Cache-Control", "no-cache, max-age=10");
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -142,7 +142,7 @@ public class TestRequestProtocolCompliance {
throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setHeader("Cache-Control", "min-fresh=10");
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertEquals("min-fresh=10",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -153,7 +153,7 @@ public class TestRequestProtocolCompliance {
throws Exception {
final HttpRequest req = new BasicHttpRequest("GET", "/");
req.setHeader("Cache-Control", "no-cache,min-fresh=10,no-store");
- final HttpRequest wrapper = RequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache,no-store",
wrapper.getFirstHeader("Cache-Control").getValue());
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
index c8cf2d7..b00d6d7 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
@@ -30,12 +30,12 @@ import java.util.Date;
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.methods.HttpGet;
-import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.junit.Before;
import org.junit.Test;
@@ -64,7 +64,7 @@ public class TestResponseProtocolCompliance {
@Test(expected=ClientProtocolException.class)
public void throwsExceptionIfOriginReturnsPartialResponseWhenNotRequested() throws Exception {
final HttpGet req = new HttpGet("http://foo.example.com/");
- final HttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req);
+ final HttpRequest wrapper = BasicRequestBuilder.copy(req).build();
final int nbytes = 128;
final HttpResponse resp = makePartialResponse(nbytes);
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java
index 39220e7..d562e1a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java
@@ -33,7 +33,10 @@ import org.apache.hc.core5.http.HttpMessage;
* Abstract HTTP message copier.
*
* @since 5.0
+ *
+ * @deprecated Use message builders.
*/
+@Deprecated
public interface MessageCopier<T extends HttpMessage> {
T copy(T object);
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java
index 0c90fbc..7364a92 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java
@@ -36,7 +36,10 @@ import org.apache.hc.core5.http.message.BasicHttpRequest;
* {@link HttpRequest} copier.
*
* @since 5.0
+ *
+ * @deprecated Use {@link org.apache.hc.core5.http.support.BasicRequestBuilder}
*/
+@Deprecated
public final class RequestCopier implements MessageCopier<HttpRequest> {
public static final RequestCopier INSTANCE = new RequestCopier();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java
index 0a9d310..8111828 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncHttpRequestRetryExec.java
@@ -33,7 +33,6 @@ import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.async.AsyncExecCallback;
import org.apache.hc.client5.http.async.AsyncExecChain;
import org.apache.hc.client5.http.async.AsyncExecChainHandler;
-import org.apache.hc.client5.http.impl.RequestCopier;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.Internal;
@@ -45,6 +44,7 @@ import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.nio.AsyncDataConsumer;
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
import org.apache.hc.core5.http.nio.entity.NoopEntityConsumer;
+import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.apache.hc.core5.util.Args;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -93,7 +93,7 @@ public final class AsyncHttpRequestRetryExec implements AsyncExecChainHandler {
final String exchangeId = scope.exchangeId;
- chain.proceed(RequestCopier.INSTANCE.copy(request), entityProducer, scope, new AsyncExecCallback() {
+ chain.proceed(BasicRequestBuilder.copy(request).build(), entityProducer, scope, new AsyncExecCallback() {
@Override
public AsyncDataConsumer handleResponse(
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java
index a8f145f..0b08573 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalAbstractHttpAsyncClient.java
@@ -47,7 +47,6 @@ import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.CookieSpecFactory;
import org.apache.hc.client5.http.cookie.CookieStore;
import org.apache.hc.client5.http.impl.ExecSupport;
-import org.apache.hc.client5.http.impl.RequestCopier;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.routing.RoutingSupport;
import org.apache.hc.core5.concurrent.ComplexFuture;
@@ -68,6 +67,7 @@ import org.apache.hc.core5.http.nio.DataStreamChannel;
import org.apache.hc.core5.http.nio.HandlerFactory;
import org.apache.hc.core5.http.nio.RequestChannel;
import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.http.support.BasicRequestBuilder;
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.io.ModalCloseable;
import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
@@ -191,7 +191,7 @@ abstract class InternalAbstractHttpAsyncClient extends AbstractHttpAsyncClientBa
clientContext, execRuntime);
final AtomicBoolean outputTerminated = new AtomicBoolean(false);
execChain.execute(
- RequestCopier.INSTANCE.copy(request),
+ BasicRequestBuilder.copy(request).build(),
entityDetails != null ? new AsyncEntityProducer() {
@Override
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java
index 8621d1c..8c260b7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java
@@ -37,7 +37,10 @@ import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
* {@link ClassicHttpRequest} copier.
*
* @since 5.0
+ *
+ * @deprecated Use {@link org.apache.hc.core5.http.io.support.ClassicRequestBuilder}
*/
+@Deprecated
public final class ClassicRequestCopier implements MessageCopier<ClassicHttpRequest> {
public static final ClassicRequestCopier INSTANCE = new ClassicRequestCopier();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
index bea13a4..ffed450 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
@@ -33,8 +33,8 @@ import org.apache.hc.client5.http.HttpRequestRetryStrategy;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecChain.Scope;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.classic.ExecChainHandler;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -43,6 +43,7 @@ import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.NoHttpResponseException;
+import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.TimeValue;
import org.slf4j.Logger;
@@ -110,7 +111,7 @@ public class HttpRequestRetryExec implements ExecChainHandler {
LOG.info("Recoverable I/O exception ({}) caught when processing request to {}",
ex.getClass().getName(), route);
}
- currentRequest = ClassicRequestCopier.INSTANCE.copy(scope.originalRequest);
+ currentRequest = ClassicRequestBuilder.copy(scope.originalRequest).build();
continue;
} else {
if (ex instanceof NoHttpResponseException) {
@@ -146,7 +147,7 @@ public class HttpRequestRetryExec implements ExecChainHandler {
throw new InterruptedIOException();
}
}
- currentRequest = ClassicRequestCopier.INSTANCE.copy(scope.originalRequest);
+ currentRequest = ClassicRequestBuilder.copy(scope.originalRequest).build();
} else {
return response;
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java
index aa59a57..7138c05 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java
@@ -58,6 +58,7 @@ import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.config.Lookup;
import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.protocol.BasicHttpContext;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.io.CloseMode;
@@ -175,7 +176,7 @@ class InternalHttpClient extends CloseableHttpClient implements Configurable {
final ExecRuntime execRuntime = new InternalExecRuntime(LOG, connManager, requestExecutor,
request instanceof CancellableDependency ? (CancellableDependency) request : null);
final ExecChain.Scope scope = new ExecChain.Scope(exchangeId, route, request, execRuntime, localcontext);
- final ClassicHttpResponse response = this.execChain.execute(ClassicRequestCopier.INSTANCE.copy(request), scope);
+ final ClassicHttpResponse response = this.execChain.execute(ClassicRequestBuilder.copy(request).build(), scope);
return CloseableHttpResponse.adapt(response);
} catch (final HttpException httpException) {
throw new ClientProtocolException(httpException.getMessage(), httpException);
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
index c9ce01c..83a1b83 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
@@ -44,6 +44,7 @@ import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.TimeValue;
import org.junit.Assert;
@@ -185,7 +186,7 @@ public class TestHttpRequestRetryExec {
Mockito.eq(1),
Mockito.<HttpContext>any())).thenReturn(Boolean.TRUE);
final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context);
- final ClassicHttpRequest request = ClassicRequestCopier.INSTANCE.copy(originalRequest);
+ final ClassicHttpRequest request = ClassicRequestBuilder.copy(originalRequest).build();
try {
retryExec.execute(request, scope, chain);
} catch (final IOException ex) {
@@ -209,7 +210,7 @@ public class TestHttpRequestRetryExec {
Mockito.when(endpoint.isExecutionAborted()).thenReturn(true);
final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context);
- final ClassicHttpRequest request = ClassicRequestCopier.INSTANCE.copy(originalRequest);
+ final ClassicHttpRequest request = ClassicRequestBuilder.copy(originalRequest).build();
try {
retryExec.execute(request, scope, chain);
} catch (final IOException ex) {
@@ -254,7 +255,7 @@ public class TestHttpRequestRetryExec {
Mockito.eq(1),
Mockito.<HttpContext>any())).thenReturn(Boolean.TRUE);
final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context);
- final ClassicHttpRequest request = ClassicRequestCopier.INSTANCE.copy(originalRequest);
+ final ClassicHttpRequest request = ClassicRequestBuilder.copy(originalRequest).build();
try {
retryExec.execute(request, scope, chain);
} catch (final IOException ex) {