您的下游應用程序應該尊重x-forwarded- *標頭,並且不會生成類似的重定向。但是下面的過濾器無論如何都會改變你的重定向位置:
@Override
public String filterType() {
return "post";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
int status = RequestContext.getCurrentContext().getResponseStatusCode();
return status >= 300 && status < 400;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Map<String, String> requestHeaders = ctx.getZuulRequestHeaders();
Optional<Pair<String, String>> locationHeader = ctx.getZuulResponseHeaders()
.stream()
.filter(stringStringPair -> LOCATION.equals(stringStringPair.first()))
.findFirst();
if (locationHeader.isPresent()) {
String oldLocation = locationHeader.get().second();
String newLocation = ...
locationHeader.get().setSecond(newLocation);
}
return null;
}
那麼你是否嘗試使用Zuul過濾器來做到這一點,它不起作用? –
是不行的 –
你能否提供樣本申請? –