From fd71ace2d9c5fed8e45e1bf4ea091ebda2524f4f Mon Sep 17 00:00:00 2001 From: ztzh_xieyun Date: Thu, 9 May 2024 11:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=A7=A3=E5=AF=86=E5=8F=AA=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20content-=20type=20:=20application/json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sf/vertx/constans/SacErrorCode.java | 1 + .../io/vertx/httpproxy/impl/ReverseProxy.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sf-vertx/src/main/java/com/sf/vertx/constans/SacErrorCode.java b/sf-vertx/src/main/java/com/sf/vertx/constans/SacErrorCode.java index e369596..ac1a6c0 100644 --- a/sf-vertx/src/main/java/com/sf/vertx/constans/SacErrorCode.java +++ b/sf-vertx/src/main/java/com/sf/vertx/constans/SacErrorCode.java @@ -33,6 +33,7 @@ public class SacErrorCode { _ERROR.put(10016, "请求url被熔断"); _ERROR.put(10017, "应用请求url被限流"); _ERROR.put(10018, "apiCode与uri不匹配"); + _ERROR.put(10019, "请求不支持conetnt-type类型"); }; public static JsonObject returnErrorMsg(Integer errorCode) { diff --git a/sf-vertx/src/main/java/io/vertx/httpproxy/impl/ReverseProxy.java b/sf-vertx/src/main/java/io/vertx/httpproxy/impl/ReverseProxy.java index e9ea987..81d7043 100644 --- a/sf-vertx/src/main/java/io/vertx/httpproxy/impl/ReverseProxy.java +++ b/sf-vertx/src/main/java/io/vertx/httpproxy/impl/ReverseProxy.java @@ -393,8 +393,18 @@ public class ReverseProxy implements HttpProxy { if (isDataSecurity || circuitBreaker != null) { try { if (isDataSecurity && circuitBreaker != null) { + // 加解密,只支持application/json + String contentType = proxyRequest.headers().get(HttpHeaders.CONTENT_TYPE); + if(StringUtils.equals(contentType, "application/json") == false) { + throw new HttpException(10019); + } return breakerAndSecurity(circuitBreaker, proxyRequest); } else if (isDataSecurity) { + // 加解密,只支持application/json + String contentType = proxyRequest.headers().get(HttpHeaders.CONTENT_TYPE); + if(StringUtils.equals(contentType, "application/json") == false) { + throw new HttpException(10019); + } return security(circuitBreaker, proxyRequest); } else if (circuitBreaker != null) { return breaker(circuitBreaker, proxyRequest); @@ -404,7 +414,11 @@ public class ReverseProxy implements HttpProxy { } } catch (Exception e) { e.printStackTrace(); - throw new HttpException(10014); + int errorCode = 10014; + if (e instanceof HttpException) { + errorCode = ((HttpException) e).getStatusCode(); + } + throw new HttpException(errorCode); } } else { Future f = resolveOrigin(proxyRequest.proxiedRequest());