Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce API for not following redirects in RestClient #32795

Closed
xenoterracide opened this issue May 10, 2024 · 3 comments
Closed

Introduce API for not following redirects in RestClient #32795

xenoterracide opened this issue May 10, 2024 · 3 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@xenoterracide
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 10, 2024
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label May 12, 2024
@sbrannen sbrannen changed the title add simple api for not following redirects for rest client Introduce API for not following redirects in RestClient May 12, 2024
@bclozel
Copy link
Member

bclozel commented May 13, 2024

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.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 13, 2024
@xenoterracide
Copy link
Author

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.

@xenoterracide
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants