You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/08/09 20:50:41 UTC
[httpcomponents-client] branch master updated: HTTPCLIENT-2105:
async clients incorrectly handle redirects of requests with enclosed entity
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 f6da2ba HTTPCLIENT-2105: async clients incorrectly handle redirects of requests with enclosed entity
f6da2ba is described below
commit f6da2bac6fc891db4f7da9af9158068f3dc87e3d
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun Aug 9 19:13:18 2020 +0200
HTTPCLIENT-2105: async clients incorrectly handle redirects of requests with enclosed entity
---
.../async/AbstractHttpAsyncRedirectsTest.java | 28 ++++++++++++++++++++++
.../client5/http/impl/async/AsyncRedirectExec.java | 3 +++
2 files changed, 31 insertions(+)
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
index 1857229..31f11d3 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
@@ -377,6 +377,34 @@ public abstract class AbstractHttpAsyncRedirectsTest <T extends CloseableHttpAsy
}
@Test
+ public void testPostRedirect() throws Exception {
+ final HttpHost target = start(new Decorator<AsyncServerExchangeHandler>() {
+
+ @Override
+ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exchangeHandler) {
+ return new RedirectingAsyncDecorator(
+ exchangeHandler,
+ new OldPathRedirectResolver("/oldlocation", "/echo", HttpStatus.SC_TEMPORARY_REDIRECT));
+ }
+
+ });
+
+ final HttpClientContext context = HttpClientContext.create();
+
+ final SimpleHttpRequest post = SimpleHttpRequests.post(target, "/oldlocation/stuff");
+ post.setBody("stuff", ContentType.TEXT_PLAIN);
+ final Future<SimpleHttpResponse> future = httpclient.execute(post, context, null);
+ final HttpResponse response = future.get();
+ Assert.assertNotNull(response);
+
+ final HttpRequest request = context.getRequest();
+
+ Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
+ Assert.assertEquals("/echo/stuff", request.getRequestUri());
+ Assert.assertEquals("POST", request.getMethod());
+ }
+
+ @Test
public void testPostRedirectSeeOther() throws Exception {
final HttpHost target = start(new Decorator<AsyncServerExchangeHandler>() {
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 2803fc6..c2b331c 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
@@ -209,6 +209,9 @@ public final class AsyncRedirectExec implements AsyncExecChainHandler {
asyncExecCallback.completed();
} else {
final AsyncEntityProducer entityProducer = state.currentEntityProducer;
+ if (entityProducer != null) {
+ entityProducer.releaseResources();
+ }
if (entityProducer != null && !entityProducer.isRepeatable()) {
if (LOG.isDebugEnabled()) {
LOG.debug("{}: cannot redirect non-repeatable request", exchangeId);