Skip to content
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

fixed #5340. #5504

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
69cbe38
fixed #5340.
wlngo Mar 19, 2024
0076264
Merge branch 'master' into fix#5340
wlngo Mar 19, 2024
f7610ab
Merge branch 'master' into fix#5340
wlngo Mar 20, 2024
d64f213
Merge branch 'master' into fix#5340
847850277 Mar 21, 2024
41aa916
fix RemoteAddrKeyResolver.
wlngo Apr 7, 2024
f4c8204
Merge branch 'master' into fix#5340
wlngo Apr 8, 2024
2d28d3c
Merge branch 'master' into fix#5340
yu199195 Apr 8, 2024
2f86ed5
Merge branch 'master' into fix#5340
wlngo Apr 10, 2024
a7a77c8
Merge branch 'master' into fix#5340
wlngo Jul 30, 2024
76363b6
Merge branch 'master' into fix#5340
Aias00 Aug 14, 2024
ff32097
Merge branch 'master' into fix#5340
Aias00 Aug 30, 2024
ea7ad7b
Merge branch 'master' into fix#5340
Aias00 Aug 31, 2024
0ec3b23
Merge branch 'master' into fix#5340
damonxue Sep 12, 2024
cd01398
Merge branch 'master' into fix#5340
Aias00 Nov 15, 2024
f4cafca
Merge branch 'master' into fix#5340
Aias00 Nov 20, 2024
30e8e99
Merge branch 'master' into fix#5340
wlngo Nov 28, 2024
f3119bf
Merge branch 'master' into fix#5340
Aias00 Dec 5, 2024
cd95fb7
Merge branch 'master' into fix#5340
Aias00 Dec 5, 2024
f16ea9b
Merge branch 'master' into fix#5340
Aias00 Dec 6, 2024
1cbb45a
Merge branch 'master' into fix#5340
Aias00 Dec 9, 2024
b2d2f06
Merge branch 'master' into fix#5340
Aias00 Dec 14, 2024
ec0001c
Merge branch 'master' into fix#5340
Aias00 Dec 17, 2024
891a4c8
Merge branch 'master' into fix#5340
Aias00 Dec 19, 2024
c5b7b18
Merge branch 'master' into fix#5340
Aias00 Dec 26, 2024
8b43eaf
Merge branch 'master' into fix#5340
Aias00 Dec 26, 2024
9624a24
Merge branch 'master' into fix#5340
Aias00 Dec 27, 2024
ff09177
Merge branch 'master' into fix#5340
Aias00 Dec 31, 2024
42ab9de
Merge branch 'master' into fix#5340
Aias00 Dec 31, 2024
2e6b038
Merge branch 'master' into fix#5340
Aias00 Jan 2, 2025
81cb7fa
Merge branch 'master' into fix#5340
Aias00 Jan 2, 2025
b6ccf4f
Merge branch 'master' into fix#5340
Aias00 Jan 3, 2025
be290db
Merge branch 'master' into fix#5340
Aias00 Jan 6, 2025
f6e0d22
Merge branch 'master' into fix#5340
Aias00 Jan 9, 2025
5af3859
Merge branch 'master' into fix#5340
Aias00 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shenyu.plugin.ratelimiter.resolver;

import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.spi.Join;
import org.springframework.web.server.ServerWebExchange;

Expand All @@ -25,13 +26,39 @@
@Join
public class RemoteAddrKeyResolver implements RateLimiterKeyResolver {

private static final String[] HEADERS = {"X-Forwarded-For", "X-Real-IP", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR"};

private static final String UNKNOWN = "unknown";

@Override
public String getKeyResolverName() {
return "REMOTE_ADDRESS_KEY_RESOLVER";
}

@Override
public String resolve(final ServerWebExchange exchange) {
String ip;
for (String header : HEADERS) {
ip = exchange.getRequest().getHeaders().getFirst(header);
boolean isUnknown = StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip);
if (!isUnknown) {
if (StringUtils.indexOf(ip, ',') > 0) {
String[] split = StringUtils.split(ip, ',');
for (int i = 0; i < split.length; i++) {
split[i] = split[i].trim();
}
for (String subIp : split) {
boolean isUnknownSubIp = StringUtils.isBlank(subIp) || UNKNOWN.equalsIgnoreCase(subIp);
if (!isUnknownSubIp) {
ip = subIp;
break;
}
}
}
return ip;
}
}
return Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress();
}

}
Loading