From bc4341d10c348af884efcdea87f6dfe8f31d345e Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 16 Nov 2022 13:39:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3html=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/filter/HtmlResourceFilter.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/framework/gateway/src/main/java/io/metersphere/gateway/filter/HtmlResourceFilter.java b/framework/gateway/src/main/java/io/metersphere/gateway/filter/HtmlResourceFilter.java index 1af1e39992..5b2b028494 100644 --- a/framework/gateway/src/main/java/io/metersphere/gateway/filter/HtmlResourceFilter.java +++ b/framework/gateway/src/main/java/io/metersphere/gateway/filter/HtmlResourceFilter.java @@ -2,11 +2,10 @@ package io.metersphere.gateway.filter; import io.metersphere.commons.utils.LogUtil; import org.apache.commons.lang3.StringUtils; -import org.springframework.cloud.gateway.filter.GatewayFilter; import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.core.Ordered; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpResponse; @@ -20,7 +19,7 @@ import java.util.HashMap; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR; @Component -public class HtmlResourceFilter implements GatewayFilter, Ordered { +public class HtmlResourceFilter implements GlobalFilter, Ordered { private static final String HTTP_SCHEME = "http"; private static final HashMap NoCacheHeaders = new HashMap<>(); @@ -43,11 +42,7 @@ public class HtmlResourceFilter implements GatewayFilter, Ordered { } try { ServerHttpResponse response = exchange.getResponse(); - if (response == null) { - // maybe backend service is unavailable or other scenario? - return; - } - if (exchange.getRequest().getMethod() == HttpMethod.GET && response.getHeaders().getContentType() == MediaType.TEXT_HTML && response.getStatusCode() == HttpStatus.OK) { + if (MediaType.TEXT_HTML.equals(response.getHeaders().getContentType()) && HttpStatus.OK.equals(response.getStatusCode())) { response.getHeaders().setAll(NoCacheHeaders); } } catch (Exception e) {