0

I know that I can use ResponseBodyAdvice and that it enables me to intercept calls (just before response is written and gives access to the raw http response). Like here. But how I can configure that this should not be done for all endpoints?

Catweazle
  • 619
  • 12
  • 25
Just Cat
  • 13
  • 5

1 Answers1

0

If you're not into a generic approach then why not just add your custom response header right in your specific controller methods, e.g. like here https://www.techiedelight.com/add-header-to-response-spring-boot/. Other than that you could still use the ResponseBodyAdvice approach but would have to programmatically do the filtering, e.g. by comparing the request's path (URL) in your ResponseBodyAdvice implementation (in method beforeBodyWrite - there you have access to the request to determine the path):

T beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response)

Also see examples here: https://mtyurt.net/post/spring-modify-response-headers-after-processing.html