我正在努力使Tomcat CORS过滤器正常工作。 我将此添加到了Web应用程序的web.xml:
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
测试内容:
curl -v -H 'Origin: http://foo.com' http://localhost:8080/jobexecutor/rest/ping
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /jobexecutor/rest/ping HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> Origin: http://foo.com
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< accept: */*
< breadcrumbId: ID-7b9900644bd8-35851-1551466004858-1-23
< origin: http://foo.com
< user-agent: curl/7.58.0
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Date: Fri, 01 Mar 2019 19:05:06 GMT
<
* Connection #0 to host localhost left intact
我期望出现Access-Control-*
个标头,但没有。
如果省略Origin标头也一样。
这是Tomcat 8.0.51。
有什么想法吗?