Hello, Vlad! This is a very late answer, now you must understand all this. If someone comes across the same question, this is the answer.
Obviously, you know about the CORS filter and that Tomcat filters will only apply to servlets.
For all static content to flow through some servlet, Tomcat has a special DefaultServet - this is what you are looking for.
Basically, we just need to include it in the deployment descriptor file (for example, WEB-INF / web.xml), for example, for example:
<servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
Thus, Tomcat filters, in our case, the CORS filter will be enabled for static content.
To verify that the CORS filter actually sets headers, such as Access-Control-Allow-Origin , we will need to add another header, such as an Origin request. For example:
curl -H 'Origin: http://localhost/test' -i http:
This way you will see something like:
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Access-Control-Allow-Origin: http://localhost/test Access-Control-Allow-Credentials: true Accept-Ranges: bytes ...
Renat Bekbolatov
source share