I don't see a simple way to tell rest client to not automatically follow redirects, either on a per request way or global client level setting.

Spring v6.1.6

Comment From: bclozel

This request is quite similar to #32800. RestClient is very similar to RestTemplate as it reuses the same infrastructure and library support; the only difference is, it exposes a fluent API. We don't intend to expand the scope here, as such options really depend on the chosen HTTP library.

For example, java.net.http.HttpClient can be configured with an java.net.http.HttpClient.Redirect enum for that purpose (NEVER, ALWAYS, NORMAL with specific meanings). On the other hand, org.apache.hc.client5.http.classic.HttpClient can be configured with a org.apache.hc.client5.http.protocol.RedirectStrategy that has a different meaning and options.

Such options are better handled at the request factory level and should not be promoted at a higher level.

Comment From: xenoterracide

How do you suggest testing redirects? I'm noting this is also a limitation of WebTestClient and so related to #31275

I currently believe there may also be an oauth workflow where the original response contains data not retrievable after the redirect.

Comment From: xenoterracide

see in my test the uri I'm giving is just a fake uri, and then the test blows up because it's not real. All I'd care about is that a redirect was being successfully issued.

I'm not entirely certain what the advantage of using these facades are in 2024. I'm going to see if it's significantly more work to use a raw client.

DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "HTTP/1.1 302 [\r][\n]"                                                                                at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Vary: Origin[\r][\n]"                                                                                 at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Vary: Access-Control-Request-Method[\r][\n]"                                                          at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Vary: Access-Control-Request-Headers[\r][\n]"                                                         at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"                                                              at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "X-XSS-Protection: 0[\r][\n]"                                                                          at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Cache-Control: no-cache, no-store, max-age=0, must-revalidate[\r][\n]"                                at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Pragma: no-cache[\r][\n]"                                                                             at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Expires: 0[\r][\n]"                                                                                   at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "X-Frame-Options: DENY[\r][\n]"                                                                        at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Location: http://localhost:3000?code=XiDw6JoSH4aVKsl9y8bA3iqQ940v7mlTOuLzvHoGy2Hx4k39xaOVbjFt51OiRsbNEvGNrcd4CyiBw_CnXfYxRrWp-7-lIh8KMi12CHXtW22Rj712hssxeIFQ73RX6nmT&state=sUmww5GH[\r][\n]" at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Content-Length: 0[\r][\n]"                                                                            at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Date: Tue, 21 May 2024 19:47:29 GMT[\r][\n]"                                                          at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Keep-Alive: timeout=60[\r][\n]"                                                                       at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "Connection: keep-alive[\r][\n]"                                                                       at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)
DEBUG 1698310 - .apac.hc.clie.http.impl.Wire                            : http-outgoing-0 << "[\r][\n]"                                                                                             at org.apache.hc.client5.http.impl.Wire.wire(Wire.java:92)

I/O error on GET request for "http://localhost:39763/oauth/authorize": Connect to http://localhost:3000 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:39763/oauth/authorize": Connect to http://localhost:3000 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused
    at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.createResourceAccessException(DefaultRestClient.java:557)
    at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:482)
    at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.retrieve(DefaultRestClient.java:444)
    at com.xenoterracide.test.authorization.server.AuthorizationServerTest.authn(AuthorizationServerTest.java:98)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)