Response Headers are not exposed to the client application -Spring boot,Spring microservices
I had this problem and I want to share its solution
I have Angular application that send HTTP requests to the server and the sent process success but the response returns with no headers or at least the default minimum headers.
I need to read the token and some other information from the header.
Solution:
Response headers are not exposed by default. you must explicitly expose it in your spring boot application, in the WebSecurityConfigurerAdapter class
Add this bean to your web security
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
config.addExposedHeader("*");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
Comments