From b717fde2897c338566a95494dd392be046e5050f Mon Sep 17 00:00:00 2001 From: Kirill Usov Date: Thu, 15 Mar 2018 11:39:09 +0300 Subject: [PATCH] Information response (1xx) processing --- .../http/impl/cache/AsyncCachingExec.java | 49 +++++++++++++++++++ .../cache/DefaultAsyncCacheRevalidator.java | 6 +++ .../client5/http/async/AsyncExecCallback.java | 7 +++ .../http/impl/async/AsyncConnectExec.java | 10 ++++ .../http/impl/async/AsyncProtocolExec.java | 6 +++ .../http/impl/async/AsyncRedirectExec.java | 6 +++ .../http/impl/async/AsyncRetryExec.java | 5 ++ .../impl/async/HttpAsyncMainClientExec.java | 1 + .../InternalAbstractHttpAsyncClient.java | 6 +++ 9 files changed, 96 insertions(+) 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 2d0b69e5a..2303a2cae 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 @@ -180,6 +180,10 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler return null; } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + } + @Override public void completed() { command.run(); @@ -316,6 +320,16 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler return callback.handleResponse(backendResponse, entityDetails); } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + final AsyncExecCallback callback = callbackRef.getAndSet(null); + if (callback != null) { + callback.handleInformationResponse(response); + } else { + asyncExecCallback.handleInformationResponse(response); + } + } + @Override public void completed() { final AsyncExecCallback callback = callbackRef.getAndSet(null); @@ -501,6 +515,11 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler return asyncExecCallback.handleResponse(backendResponse, entityDetails); } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + asyncExecCallback.handleInformationResponse(response); + } + void triggerNewCacheEntryResponse(final HttpResponse backendResponse, final Date responseDate, final ByteArrayBuffer buffer) { final CancellableDependency operation = scope.cancellableDependency; operation.setDependency(responseCache.createCacheEntry( @@ -789,6 +808,16 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler return callback2.handleResponse(backendResponse2, entityDetails); } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + final AsyncExecCallback callback2 = callbackRef.getAndSet(null); + if (callback2 != null) { + callback2.handleInformationResponse(response); + } else { + asyncExecCallback.handleInformationResponse(response); + } + } + @Override public void completed() { final AsyncExecCallback callback2 = callbackRef.getAndSet(null); @@ -821,6 +850,16 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler return callback1.handleResponse(backendResponse1, entityDetails); } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + final AsyncExecCallback callback1 = callbackRef.getAndSet(null); + if (callback1 != null) { + callback1.handleInformationResponse(response); + } else { + asyncExecCallback.handleInformationResponse(response); + } + } + @Override public void completed() { final AsyncExecCallback callback1 = callbackRef.getAndSet(null); @@ -1028,6 +1067,16 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler return callback.handleResponse(backendResponse, entityDetails); } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + final AsyncExecCallback callback = callbackRef.getAndSet(null); + if (callback != null) { + callback.handleInformationResponse(response); + } else { + asyncExecCallback.handleInformationResponse(response); + } + } + @Override public void completed() { final AsyncExecCallback callback = callbackRef.getAndSet(null); diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java index 7c9b4ea9c..5468cec3e 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/DefaultAsyncCacheRevalidator.java @@ -130,6 +130,12 @@ class DefaultAsyncCacheRevalidator extends CacheRevalidatorBase { return asyncExecCallback.handleResponse(response, entityDetails); } + @Override + public void handleInformationResponse( + final HttpResponse response) throws HttpException, IOException { + asyncExecCallback.handleInformationResponse(response); + } + @Override public void completed() { final HttpResponse httpResponse = responseRef.getAndSet(null); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java index c09d2c1d1..f87c295fe 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecCallback.java @@ -54,6 +54,13 @@ public interface AsyncExecCallback { HttpResponse response, EntityDetails entityDetails) throws HttpException, IOException; + /** + * Triggered to signal receipt of an intermediate response message. + * + * @param response the intermediate response message. + */ + void handleInformationResponse(HttpResponse response) throws HttpException, IOException; + /** * Triggered to signal completion of the message exchange. *

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 8dff8c7ff..f65ffa153 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 @@ -255,6 +255,12 @@ public final class AsyncConnectExec implements AsyncExecChainHandler { return asyncExecCallback.handleResponse(response, entityDetails); } + @Override + public void handleInformationResponse( + final HttpResponse response) throws HttpException, IOException { + asyncExecCallback.handleInformationResponse(response); + } + @Override public void completed() { if (log.isDebugEnabled()) { @@ -359,6 +365,10 @@ public final class AsyncConnectExec implements AsyncExecChainHandler { return null; } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + } + @Override public void completed() { if (!execRuntime.isEndpointConnected()) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncProtocolExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncProtocolExec.java index 09a7a4557..0f18fe18d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncProtocolExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncProtocolExec.java @@ -193,6 +193,12 @@ public final class AsyncProtocolExec implements AsyncExecChainHandler { return asyncExecCallback.handleResponse(response, entityDetails); } + @Override + public void handleInformationResponse( + final HttpResponse response) throws HttpException, IOException { + asyncExecCallback.handleInformationResponse(response); + } + @Override public void completed() { if (!execRuntime.isEndpointConnected()) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java index e7dc3dea1..c8ad47d92 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java @@ -192,6 +192,12 @@ public final class AsyncRedirectExec implements AsyncExecChainHandler { return asyncExecCallback.handleResponse(response, entityDetails); } + @Override + public void handleInformationResponse( + final HttpResponse response) throws HttpException, IOException { + asyncExecCallback.handleInformationResponse(response); + } + @Override public void completed() { if (state.redirectURI == null) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java index 2cb6bb00f..d301cf061 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java @@ -92,6 +92,11 @@ public final class AsyncRetryExec implements AsyncExecChainHandler { return asyncExecCallback.handleResponse(response, entityDetails); } + @Override + public void handleInformationResponse(final HttpResponse response) throws HttpException, IOException { + asyncExecCallback.handleInformationResponse(response); + } + @Override public void completed() { asyncExecCallback.completed(); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java index 4316f78a1..f09b51f8e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java @@ -181,6 +181,7 @@ class HttpAsyncMainClientExec implements AsyncExecChainHandler { public void consumeInformation( final HttpResponse response, final HttpContext context) throws HttpException, IOException { + asyncExecCallback.handleInformationResponse(response); } @Override 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 6e3ef4a8c..58e56c046 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 @@ -263,6 +263,12 @@ abstract class InternalAbstractHttpAsyncClient extends AbstractHttpAsyncClientBa return responseConsumer; } + @Override + public void handleInformationResponse( + final HttpResponse response) throws HttpException, IOException { + responseConsumer.informationResponse(response, context); + } + @Override public void completed() { if (log.isDebugEnabled()) {