加解密只支持 content- type : application/json

This commit is contained in:
ztzh_xieyun 2024-05-09 11:54:07 +08:00
parent 13040c949e
commit fd71ace2d9
2 changed files with 16 additions and 1 deletions

View File

@ -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) {

View File

@ -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<HttpClientRequest> f = resolveOrigin(proxyRequest.proxiedRequest());