-
Couldn't load subscription status.
- Fork 38.8k
Closed as not planned
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
Default RestClient does not follow redirect (in case of 301 at least.
Response body is null
@RestController
class SampleController {
@GetMapping("/first")
fun redirectToSecond() = ResponseEntity
.status(301)
.header("Location", "/second")
.build<Unit>()
@GetMapping("/second")
fun noRedirect() = "OK"
}
@Component
class Runner(
@Value("\${server.port}")
private val port: Int
) : ApplicationRunner {
override fun run(args: ApplicationArguments?) {
// this works: redirect is followed
val entityWithRC = RestClient.builder(RestTemplate()) // <---- this
.baseUrl("http://localhost:$port")
.build()
.get()
.uri("/first")
.retrieve()
.toEntity<String>()
// this does not work: redirect is not followed
val entityWithDefaults = RestClient.builder()
.baseUrl("http://localhost:$port")
.build()
.get()
.uri("/first")
.retrieve()
.toEntity<String>()
println(entityWithRC)
println(entityWithDefaults)
}
}
Console output:
<200 OK OK,OK,[Content-Type:"text/plain;charset=UTF-8", Content-Length:"2", Date:"Thu, 17 Oct 2024 14:39:00 GMT", Keep-Alive:"timeout=60", Connection:"keep-alive"]>
<301 MOVED_PERMANENTLY Moved Permanently,[content-length:"0", date:"Thu, 17 Oct 2024 14:39:00 GMT", location:"/second"]>
Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.comin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid