HTTPCLIENT-2105: async clients incorrectly handle redirects of requests with enclosed entity

This commit is contained in:
Oleg Kalnichevski 2020-08-09 19:13:18 +02:00
parent 889159b977
commit f6da2bac6f
2 changed files with 31 additions and 0 deletions

View File

@ -376,6 +376,34 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
}
}
@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>() {

View File

@ -209,6 +209,9 @@ public void completed() {
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);