update: extractServiceOrAddress method support parameter which like 'https://www.baidu.com'
This commit is contained in:
@@ -220,8 +220,17 @@ public class FizzWebClient {
|
||||
// TODO 请求完成后,做metric, 以反哺后续的请求转发
|
||||
}
|
||||
|
||||
private String extractServiceOrAddress(String uriOrSvc) {
|
||||
return uriOrSvc.substring(7, uriOrSvc.indexOf(Constants.Symbol.FORWARD_SLASH, 10));
|
||||
public String extractServiceOrAddress(String uriOrSvc) {
|
||||
char c4 = uriOrSvc.charAt(4);
|
||||
int start = 7, end = uriOrSvc.length();
|
||||
if (c4 == 's' || c4 == 'S') {
|
||||
start = 8;
|
||||
}
|
||||
int i = uriOrSvc.indexOf(Constants.Symbol.FORWARD_SLASH, 9);
|
||||
if (i > 0) {
|
||||
end = i;
|
||||
}
|
||||
return uriOrSvc.substring(start, end);
|
||||
}
|
||||
|
||||
private boolean isService(String s) {
|
||||
|
||||
38
src/test/java/we/proxy/FizzWebClientTests.java
Normal file
38
src/test/java/we/proxy/FizzWebClientTests.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package we.proxy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author hongqiaowei
|
||||
*/
|
||||
|
||||
public class FizzWebClientTests {
|
||||
|
||||
@Test
|
||||
void extractServiceOrAddressTest() {
|
||||
FizzWebClient fizzWebClient = new FizzWebClient();
|
||||
|
||||
String r0 = fizzWebClient.extractServiceOrAddress("http://www.baidu.com");
|
||||
assertEquals(r0, "www.baidu.com");
|
||||
|
||||
String r1 = fizzWebClient.extractServiceOrAddress("https://www.baidu.com");
|
||||
assertEquals(r1, "www.baidu.com");
|
||||
|
||||
String r2 = fizzWebClient.extractServiceOrAddress("https://aservice");
|
||||
assertEquals(r2, "aservice");
|
||||
|
||||
String r3 = fizzWebClient.extractServiceOrAddress("https://aservice/ypath");
|
||||
assertEquals(r3, "aservice");
|
||||
|
||||
String r4 = fizzWebClient.extractServiceOrAddress("https://127.0.0.1");
|
||||
assertEquals(r4, "127.0.0.1");
|
||||
|
||||
String r5 = fizzWebClient.extractServiceOrAddress("https://127.0.0.1:8600");
|
||||
assertEquals(r5, "127.0.0.1:8600");
|
||||
|
||||
String r6 = fizzWebClient.extractServiceOrAddress("http://127.0.0.1:8600/apath");
|
||||
assertEquals(r6, "127.0.0.1:8600");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user