Skip to content

Commit

Permalink
Merge #2673 into 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Jan 27, 2023
2 parents 0dbe917 + ec43652 commit 31b673e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,19 @@ protected HttpMessage outboundHttpMessage() {

final boolean notRedirected(HttpResponse response) {
if (isFollowRedirect() && followRedirectPredicate.test(this, this)) {
try {
redirecting = new RedirectClientException(response.headers(), response.status());
}
catch (RuntimeException e) {
if (log.isDebugEnabled()) {
log.debug(format(channel(), "The request cannot be redirected"), e);
}
return true;
}
if (log.isDebugEnabled()) {
log.debug(format(channel(), "Received redirect location: {}"),
httpMessageLogFactory().debug(HttpMessageArgProviderFactory.create(response)));
}
redirecting = new RedirectClientException(response.headers(), response.status());
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2011-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,8 +31,8 @@ final class RedirectClientException extends RuntimeException {
final HttpResponseStatus status;

RedirectClientException(HttpHeaders headers, HttpResponseStatus status) {
location = Objects.requireNonNull(headers.get(HttpHeaderNames.LOCATION));
this.status = Objects.requireNonNull(status);
location = Objects.requireNonNull(headers.get(HttpHeaderNames.LOCATION), "location");
this.status = Objects.requireNonNull(status, "status");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2017-2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -798,4 +798,24 @@ void testHttp2Redirect() {
assertThat(response.getT2()).isEqualTo(200);
assertThat(response.getT1()).isEqualTo("OK");
}

@Test
void testIssue2670() {
disposableServer =
createServer()
.handle((req, res) -> res.sendString(Mono.just("testIssue2670")))
.bindNow();

createClient(disposableServer.port())
.followRedirect((req, res) -> true)
.get()
.uri("/")
.responseContent()
.aggregate()
.asString()
.as(StepVerifier::create)
.expectNext("testIssue2670")
.expectComplete()
.verify(Duration.ofSeconds(5));
}
}

0 comments on commit 31b673e

Please sign in to comment.