Skip to content

Commit 31b673e

Browse files
committed
Merge #2673 into 1.1.3
2 parents 0dbe917 + ec43652 commit 31b673e

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientOperations.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,19 @@ protected HttpMessage outboundHttpMessage() {
741741

742742
final boolean notRedirected(HttpResponse response) {
743743
if (isFollowRedirect() && followRedirectPredicate.test(this, this)) {
744+
try {
745+
redirecting = new RedirectClientException(response.headers(), response.status());
746+
}
747+
catch (RuntimeException e) {
748+
if (log.isDebugEnabled()) {
749+
log.debug(format(channel(), "The request cannot be redirected"), e);
750+
}
751+
return true;
752+
}
744753
if (log.isDebugEnabled()) {
745754
log.debug(format(channel(), "Received redirect location: {}"),
746755
httpMessageLogFactory().debug(HttpMessageArgProviderFactory.create(response)));
747756
}
748-
redirecting = new RedirectClientException(response.headers(), response.status());
749757
return false;
750758
}
751759
return true;

reactor-netty-http/src/main/java/reactor/netty/http/client/RedirectClientException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2022 VMware, Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2011-2023 VMware, Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,8 @@ final class RedirectClientException extends RuntimeException {
3131
final HttpResponseStatus status;
3232

3333
RedirectClientException(HttpHeaders headers, HttpResponseStatus status) {
34-
location = Objects.requireNonNull(headers.get(HttpHeaderNames.LOCATION));
35-
this.status = Objects.requireNonNull(status);
34+
location = Objects.requireNonNull(headers.get(HttpHeaderNames.LOCATION), "location");
35+
this.status = Objects.requireNonNull(status, "status");
3636
}
3737

3838
@Override

reactor-netty-http/src/test/java/reactor/netty/http/client/HttpRedirectTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2022 VMware, Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2017-2023 VMware, Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -798,4 +798,24 @@ void testHttp2Redirect() {
798798
assertThat(response.getT2()).isEqualTo(200);
799799
assertThat(response.getT1()).isEqualTo("OK");
800800
}
801+
802+
@Test
803+
void testIssue2670() {
804+
disposableServer =
805+
createServer()
806+
.handle((req, res) -> res.sendString(Mono.just("testIssue2670")))
807+
.bindNow();
808+
809+
createClient(disposableServer.port())
810+
.followRedirect((req, res) -> true)
811+
.get()
812+
.uri("/")
813+
.responseContent()
814+
.aggregate()
815+
.asString()
816+
.as(StepVerifier::create)
817+
.expectNext("testIssue2670")
818+
.expectComplete()
819+
.verify(Duration.ofSeconds(5));
820+
}
801821
}

0 commit comments

Comments
 (0)