Link to home
Create AccountLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

how to set common header for all RequestMappings in a controller

Hi,
In my controller i have the following line in each requestMapping method :
        response.setHeader(contentSecurityolicy.getHttpHeader(), contentSecurityPolicy.toString());

Open in new window


There are 4 such methods... Is there any way i can avoid this so as to specify this header only once in controller and
it gets added to all the responses ?


Thanks
Avatar of Rohit Bajaj
Rohit Bajaj
Flag of India image

ASKER

Also in some codebase i saw that they created a filter for adding content security policy header.
Whats the correct approach as per designing ?
Should i just add it like above in each request mapping.. or create a filter and so controller does not know about adding of this header ?
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer