修改代理 IP 获取设置,新增 GeoLite 本地归属地查询,修正 devtools 配置导致 ByteBuddy 重定义方法类
ClassLoader 不一致,进一步导致重定义方法内无法获取到自定义规则的问题
This commit is contained in:
@@ -3,10 +3,12 @@ package quant.rich;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import quant.rich.emoney.patch.okhttp.RequestContext;
|
||||
import quant.rich.emoney.patch.okhttp.PatchOkHttp;
|
||||
import quant.rich.emoney.patch.okhttp.PatchOkHttpRule;
|
||||
|
||||
public class PatchOkHttpTest {
|
||||
@@ -22,18 +24,33 @@ public class PatchOkHttpTest {
|
||||
|
||||
Assertions.assertTrue(rule.matches(context), "测试失败");
|
||||
|
||||
rule = PatchOkHttpRule.when().hostEndsWith("emoney.com")
|
||||
.or(r -> r.hostContains("emapp"))
|
||||
rule = PatchOkHttpRule.when().hostEndsWith("emoney.cn")
|
||||
.or(c -> c.hostContains("localhost"))
|
||||
.or(a -> a.hostContains("emapp"))
|
||||
.or(b -> b.hasHeaderName("X-Protocol-Id"))
|
||||
.overrideIf("User-Agent", "okhttp/3.12.2")
|
||||
.build();
|
||||
context = new RequestContext(Map.of(), "https", "mbs.emoney.com");
|
||||
context = new RequestContext(Map.of(), "https", "mbs.emoney.cn");
|
||||
|
||||
Assertions.assertTrue(rule.matches(context), "测试失败");
|
||||
|
||||
context = new RequestContext(Map.of(), "https", "emapp-static.oss-cn-shanghai.aliyuncs.com");
|
||||
Assertions.assertTrue(rule.matches(context), "测试失败");
|
||||
|
||||
// 测试 Override
|
||||
String[] modifier = new String[] {""};
|
||||
Consumer<String> consumer = str -> {
|
||||
modifier[0] = str;
|
||||
};
|
||||
PatchOkHttp.apply(rule);
|
||||
PatchOkHttp.match(context, "User-Agent", consumer);
|
||||
Assertions.assertTrue("okhttp/3.12.2".equals(modifier[0]), "测试失败:User-Agent 覆写失败");
|
||||
|
||||
modifier[0] = "";
|
||||
context = new RequestContext(Map.of(), "https", "hao123.com");
|
||||
Assertions.assertFalse(rule.matches(context), "测试失败");
|
||||
PatchOkHttp.match(context, "User-Agent", consumer);
|
||||
Assertions.assertTrue("".equals(modifier[0]), "测试失败:User-Agent 不覆写失败");
|
||||
|
||||
|
||||
//Assertions.assertEquals("{\"info\":\"m\",\"weight\":\"100kg/m\"}", JSON.toJSONString(humanWeight));
|
||||
|
||||
Reference in New Issue
Block a user