Spring Cloud RewriteLocationResponseHeader GatewayFilter工厂
RewriteLocationResponseHeader GatewayFilter工厂通常会修改Location响应标头的值,以摆脱后端特定的详细信息。它需要stripVersionMode,locationHeaderName,hostValue和protocolsRegex参数。
application.yml。
spring: cloud: gateway: routes: - id: rewritelocationresponseheader_route uri: http://example.org filters: - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, ,
例如,对于请求POST https://api.example.com/some/object/name,Location响应标头值https://object-service.prod.example.net/v2/some/object/id将被重写为https://api.example.com/some/object/id。
参数stripVersionMode具有以下可能的值:NEVER_STRIP,AS_IN_REQUEST(默认),ALWAYS_STRIP。
NEVER_STRIP-即使原始请求路径不包含版本,也不会剥离版本AS_IN_REQUEST-仅当原始请求路径不包含版本时,版本才会被剥离ALWAYS_STRIP-即使原始请求路径包含版本,也会剥离版本
参数hostValue(如果提供)将用于替换响应Location标头中的host:port部分。如果未提供,将使用Host请求标头的值。
参数protocolsRegex必须是有效的正则表达式String,协议名称将与之匹配。如果不匹配,过滤器将不执行任何操作。默认值为http|https|ftp|ftps。