-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for customizing ConfigurableRequestItemParser for SC gateway and Zuul adapter #2542
Conversation
...ava/com/alibaba/csp/sentinel/adapter/gateway/common/param/ConfigurableRequestItemParser.java
Show resolved
Hide resolved
...c/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/filters/SentinelZuulPreFilter.java
Outdated
Show resolved
Hide resolved
...adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/sc/SentinelGatewayFilter.java
Outdated
Show resolved
Hide resolved
...ava/com/alibaba/csp/sentinel/adapter/gateway/common/param/ConfigurableRequestItemParser.java
Show resolved
Hide resolved
...ava/com/alibaba/csp/sentinel/adapter/gateway/common/param/ConfigurableRequestItemParser.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will solve it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
return delegate.getCookieValue(request, cookieName); | ||
} | ||
|
||
public void addPathExtractor(Function<T, String> extractor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe fluent-style API seems better? Just return this
like a builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that's a good suggestion. I'll change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for contributing! |
…way and Zuul adapter (alibaba#2542) * Add ConfigurableRequestItemParser and support customize RequestItemParser * fluent-style API
Describe what this PR does / why we need it
#2456 放开SentinelGatewayFilter写死ServerWebExchangeItemParser的逻辑,支持对参数获取的扩展,增加灵活性
Does this pull request fix one issue?
#2456
Describe how you did it
新增ConfigurableRequestItemParser,可以通过添加Function<T,R>的方式扩充解析逻辑
Describe how to verify it
在装配SentinelGatewayFilter前,先配置remoteAddress的获取逻辑。
nginx代理时需要在第一级代理的header中添加 X-Real-IP,proxy_set_header X-Real-IP $remote_addr;
List headerNames = Arrays.asList("X-Real-IP", "Client-IP");
//delegate default parser and add extractor
ConfigurableRequestItemParser requestItemParser = new ConfigurableRequestItemParser<>(new ServerWebExchangeItemParser());
requestItemParser.addRemoteAddressExtractor(serverWebExchange -> {
for (String headerKey : headerNames) {
String remoteAddress = serverWebExchange.getRequest().getHeaders().getFirst(headerKey);
if (StringUtils.hasLength(remoteAddress)) {
return remoteAddress;
}
}
return null;
});
return new SentinelGatewayFilter(requestItemParser);