上传文件自动判断,不走加解密熔断
This commit is contained in:
parent
135f4a0b8f
commit
b7518b3ffd
@ -31,6 +31,7 @@ import io.vertx.circuitbreaker.CircuitBreaker;
|
||||
import io.vertx.circuitbreaker.CircuitBreakerOptions;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.VertxOptions;
|
||||
import io.vertx.core.http.HttpHeaders;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/***
|
||||
@ -93,6 +94,17 @@ public class AppConfigHandle {
|
||||
return APICODE_CONFIG_CIRCUIT_BREAKER_MAP.get(key);
|
||||
}
|
||||
|
||||
/***
|
||||
* 是否解析, 走独立请求
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAnalysisBody(String appCode, String apiCode, String contentType) {
|
||||
String keyCircuitBreaker = appCode + ":" + apiCode + ":" + "CIRCUIT_BREAKER";
|
||||
CircuitBreaker circuitBreaker = AppConfigHandle.getApiCodeCircuitBreaker(keyCircuitBreaker);
|
||||
boolean isDataSecurity = AppConfigHandle.isDataSecurity(appCode);
|
||||
// 文件上传不走加解密
|
||||
return (isDataSecurity || circuitBreaker != null) && StringUtils.startsWith(contentType, "multipart") == false;
|
||||
}
|
||||
/***
|
||||
* 优先apicode配置限流、无法找到匹配全局限流
|
||||
*
|
||||
|
@ -80,15 +80,11 @@ public class BodyHandlerImpl implements BodyHandler {
|
||||
final HttpServerResponse response = context.response();
|
||||
String appCode = context.request().headers().get(AppConfigHandle.getAppCodeHeaderKey());
|
||||
String apiCode = context.request().headers().get(AppConfigHandle.getApiCodeHeaderKey());
|
||||
// 判断<br/>
|
||||
// 1、是否配置全局加解密.<br/>
|
||||
// 2、apiCode 配置熔断
|
||||
String keyCircuitBreaker = appCode + ":" + apiCode + ":" + "CIRCUIT_BREAKER";
|
||||
String contentType = context.request().headers().get(HttpHeaders.CONTENT_TYPE);
|
||||
boolean isLoadBody = false;
|
||||
try {
|
||||
// TODO 测试异常
|
||||
isLoadBody = AppConfigHandle.isDataSecurity(appCode)
|
||||
|| AppConfigHandle.isApiCodeCircuitBreaker(keyCircuitBreaker);
|
||||
isLoadBody = AppConfigHandle.isAnalysisBody(appCode, apiCode, contentType);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
context.fail(new HttpException(SacErrorCode.DEFAULT_ERROR_CODE));
|
||||
|
@ -387,24 +387,14 @@ public class ReverseProxy implements HttpProxy {
|
||||
// 2、apiCode 配置熔断
|
||||
String appCode = proxyRequest.headers().get(AppConfigHandle.getAppCodeHeaderKey());
|
||||
String apiCode = proxyRequest.headers().get(AppConfigHandle.getApiCodeHeaderKey());
|
||||
String contentType = proxyRequest.headers().get(HttpHeaders.CONTENT_TYPE);
|
||||
String keyCircuitBreaker = appCode + ":" + apiCode + ":" + "CIRCUIT_BREAKER";
|
||||
CircuitBreaker circuitBreaker = AppConfigHandle.getApiCodeCircuitBreaker(keyCircuitBreaker);
|
||||
boolean isDataSecurity = AppConfigHandle.isDataSecurity(appCode);
|
||||
if (isDataSecurity || circuitBreaker != null) {
|
||||
if (AppConfigHandle.isAnalysisBody(appCode, apiCode, contentType)) {
|
||||
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);
|
||||
}
|
||||
if (AppConfigHandle.isDataSecurity(appCode) && circuitBreaker != null) {
|
||||
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);
|
||||
}
|
||||
} else if (AppConfigHandle.isDataSecurity(appCode)) {
|
||||
return security(circuitBreaker, proxyRequest);
|
||||
} else if (circuitBreaker != null) {
|
||||
return breaker(circuitBreaker, proxyRequest);
|
||||
|
Loading…
x
Reference in New Issue
Block a user