RemoveResponseHeader
Filter
RemoveResponseHeader
过滤器采用 name
参数。它是将被移除的标头的名称。以下清单配置了一个 RemoveResponseHeader
过滤器:
The RemoveResponseHeader
filter takes a name
parameter.
It is the name of the header to be removed.
The following listing configures a RemoveResponseHeader
filter:
application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: removeresponseheader_route
uri: https://example.org
filters:
- RemoveResponseHeader=X-Response-Foo
GatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.removeResponseHeader;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
@Configuration
class RouteConfiguration {
@Bean
public RouterFunction<ServerResponse> gatewayRouterFunctionsRemoveResponseHeader() {
return route("addresponseheader")
.GET("/anything/addresheader", http("https://example.org"))
.after(removeResponseHeader("X-Response-Foo"))
.build();
}
}
它会从返回到网关客户端的响应中移除 X-Response-Foo
标头。
This will remove the X-Response-Foo
header from the response before it is returned to the gateway client.
若要移除任何敏感的标头,您应为所有可能这么做的路由配置此过滤器。此外,您可以使用 spring.cloud.gateway.default-filters
配置此过滤器,并将其应用到所有路由。
To remove any kind of sensitive header, you should configure this filter for any routes for which you may want to do so.
In addition, you can configure this filter once by using spring.cloud.gateway.default-filters
and have it applied to all routes.