修改代理 IP 获取设置,新增 GeoLite 本地归属地查询,修正 devtools 配置导致 ByteBuddy 重定义方法类
ClassLoader 不一致,进一步导致重定义方法内无法获取到自定义规则的问题
This commit is contained in:
@@ -4,6 +4,11 @@ import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import quant.rich.emoney.patch.okhttp.PatchOkHttp.HeaderInterceptor;
|
||||
|
||||
public class PatchOkHttpRule {
|
||||
private final Predicate<RequestContext> condition;
|
||||
private final List<HeaderAction> actions;
|
||||
@@ -37,6 +42,7 @@ public class PatchOkHttpRule {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public static final Logger log = LoggerFactory.getLogger(HeaderInterceptor.class);
|
||||
private Predicate<RequestContext> condition;
|
||||
private final List<HeaderAction> actions = new ArrayList<>();
|
||||
|
||||
@@ -51,6 +57,10 @@ public class PatchOkHttpRule {
|
||||
public Builder hasHeaderName(String name) {
|
||||
return and(ctx -> ctx.headers.containsKey(name));
|
||||
}
|
||||
|
||||
public Builder hasNotHeaderName(String name) {
|
||||
return not(r -> r.and(ctx -> ctx.headers.containsKey(name)));
|
||||
}
|
||||
|
||||
public Builder hasHeaderValueMatch(String name, String regex) {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
@@ -138,6 +148,8 @@ public class PatchOkHttpRule {
|
||||
public Builder overrideIf(String headerName, String value) {
|
||||
actions.add((ctx, curr, setter) -> {
|
||||
if (curr.equalsIgnoreCase(headerName)) {
|
||||
log.debug("matches and applying - host: {}, currHeader {}, targetHeader {}, value: {}, classLoader: {}", ctx.host, curr, headerName,
|
||||
value, this.getClass().getClassLoader());
|
||||
setter.accept(value);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user