@ -25,6 +25,7 @@ import java.util.Set;
import javax.annotation.PostConstruct ;
import javax.annotation.PostConstruct ;
import com.tencent.cloud.common.constant.HeaderConstant ;
import com.tencent.cloud.common.metadata.MetadataContext ;
import com.tencent.cloud.common.metadata.MetadataContext ;
import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitProperties ;
import com.tencent.cloud.polaris.ratelimit.config.PolarisRateLimitProperties ;
import com.tencent.cloud.polaris.ratelimit.constant.RateLimitConstant ;
import com.tencent.cloud.polaris.ratelimit.constant.RateLimitConstant ;
@ -32,6 +33,7 @@ import com.tencent.cloud.polaris.ratelimit.resolver.RateLimitRuleArgumentReactiv
import com.tencent.cloud.polaris.ratelimit.spi.PolarisRateLimiterLimitedFallback ;
import com.tencent.cloud.polaris.ratelimit.spi.PolarisRateLimiterLimitedFallback ;
import com.tencent.cloud.polaris.ratelimit.utils.QuotaCheckUtils ;
import com.tencent.cloud.polaris.ratelimit.utils.QuotaCheckUtils ;
import com.tencent.cloud.polaris.ratelimit.utils.RateLimitUtils ;
import com.tencent.cloud.polaris.ratelimit.utils.RateLimitUtils ;
import com.tencent.polaris.api.pojo.RetStatus ;
import com.tencent.polaris.ratelimit.api.core.LimitAPI ;
import com.tencent.polaris.ratelimit.api.core.LimitAPI ;
import com.tencent.polaris.ratelimit.api.rpc.Argument ;
import com.tencent.polaris.ratelimit.api.rpc.Argument ;
import com.tencent.polaris.ratelimit.api.rpc.QuotaResponse ;
import com.tencent.polaris.ratelimit.api.rpc.QuotaResponse ;
@ -70,9 +72,9 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
private String rejectTips ;
private String rejectTips ;
public QuotaCheckReactiveFilter ( LimitAPI limitAPI ,
public QuotaCheckReactiveFilter ( LimitAPI limitAPI ,
PolarisRateLimitProperties polarisRateLimitProperties ,
PolarisRateLimitProperties polarisRateLimitProperties ,
RateLimitRuleArgumentReactiveResolver rateLimitRuleArgumentResolver ,
RateLimitRuleArgumentReactiveResolver rateLimitRuleArgumentResolver ,
@Nullable PolarisRateLimiterLimitedFallback polarisRateLimiterLimitedFallback ) {
@Nullable PolarisRateLimiterLimitedFallback polarisRateLimiterLimitedFallback ) {
this . limitAPI = limitAPI ;
this . limitAPI = limitAPI ;
this . polarisRateLimitProperties = polarisRateLimitProperties ;
this . polarisRateLimitProperties = polarisRateLimitProperties ;
this . rateLimitRuleArgumentResolver = rateLimitRuleArgumentResolver ;
this . rateLimitRuleArgumentResolver = rateLimitRuleArgumentResolver ;
@ -108,8 +110,7 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
response . setRawStatusCode ( polarisRateLimiterLimitedFallback . rejectHttpCode ( ) ) ;
response . setRawStatusCode ( polarisRateLimiterLimitedFallback . rejectHttpCode ( ) ) ;
response . getHeaders ( ) . setContentType ( polarisRateLimiterLimitedFallback . mediaType ( ) ) ;
response . getHeaders ( ) . setContentType ( polarisRateLimiterLimitedFallback . mediaType ( ) ) ;
dataBuffer = response . bufferFactory ( ) . allocateBuffer ( )
dataBuffer = response . bufferFactory ( ) . allocateBuffer ( )
. write ( polarisRateLimiterLimitedFallback . rejectTips ( )
. write ( polarisRateLimiterLimitedFallback . rejectTips ( ) . getBytes ( polarisRateLimiterLimitedFallback . charset ( ) ) ) ;
. getBytes ( polarisRateLimiterLimitedFallback . charset ( ) ) ) ;
}
}
else {
else {
response . setRawStatusCode ( polarisRateLimitProperties . getRejectHttpCode ( ) ) ;
response . setRawStatusCode ( polarisRateLimitProperties . getRejectHttpCode ( ) ) ;
@ -117,6 +118,10 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
dataBuffer = response . bufferFactory ( ) . allocateBuffer ( )
dataBuffer = response . bufferFactory ( ) . allocateBuffer ( )
. write ( rejectTips . getBytes ( StandardCharsets . UTF_8 ) ) ;
. write ( rejectTips . getBytes ( StandardCharsets . UTF_8 ) ) ;
}
}
response . getHeaders ( ) . add ( HeaderConstant . INTERNAL_CALLEE_RET_STATUS , RetStatus . RetFlowControl . getDesc ( ) ) ;
if ( Objects . nonNull ( quotaResponse . getActiveRule ( ) ) ) {
response . getHeaders ( ) . add ( HeaderConstant . INTERNAL_ACTIVE_RULE_NAME , quotaResponse . getActiveRule ( ) . getName ( ) . getValue ( ) ) ;
}
return response . writeWith ( Mono . just ( dataBuffer ) ) ;
return response . writeWith ( Mono . just ( dataBuffer ) ) ;
}
}
// Unirate
// Unirate