Add support for customizing ConfigurableRequestItemParser for SC gateway and Zuul adapter#2542
Merged
sczyh30 merged 4 commits intoalibaba:masterfrom Jan 20, 2022
icodening:master
Merged
Add support for customizing ConfigurableRequestItemParser for SC gateway and Zuul adapter#2542sczyh30 merged 4 commits intoalibaba:masterfrom icodening:master
sczyh30 merged 4 commits intoalibaba:masterfrom
icodening:master
Conversation
brotherlu-xcq
requested changes
Jan 19, 2022
...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
icodening
commented
Jan 19, 2022
Contributor
Author
icodening
left a comment
There was a problem hiding this comment.
OK, I will solve it
sczyh30
reviewed
Jan 19, 2022
| return delegate.getCookieValue(request, cookieName); | ||
| } | ||
|
|
||
| public void addPathExtractor(Function<T, String> extractor) { |
Member
There was a problem hiding this comment.
Maybe fluent-style API seems better? Just return this like a builder.
Contributor
Author
There was a problem hiding this comment.
OK, that's a good suggestion. I'll change it
Member
|
Thanks for contributing! |
Zhang-0952
pushed a commit
to Zhang-0952/Sentinel
that referenced
this pull request
Mar 4, 2022
…way and Zuul adapter (alibaba#2542) * Add ConfigurableRequestItemParser and support customize RequestItemParser * fluent-style API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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);