This is my spring-boot(3.3.5)/thymeleaf application pom.xml deps:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I have a simple controller with two Get mappings.
/
./redirect
it redirects with 302 to /
as expected (the browser receives the 200 response after 302). However, I notice that the 302 response also contains the rendered page of /
. The browser essentially receives the same page twice.My controller (IndexController.java):
@Controller
public class IndexController {
@GetMapping("/")
public String index(Model model){
return "index";
}
@GetMapping("/redirect")
public String redirect(Model model){
return "redirect:/"; //302 reponse has rendered "index.html"
}
}
Thymeleaf template (/resources/templates/index.html:
<h1>hai</h1>
The 302 doesn't contain the HTML. It only shows it like this as the browser will follow it.
If you would call it with something like CURL or HTTPie you will see that the 302 response only contains a Location
header and no content.