我正在使用 BrowserMob 代理,我想将流量从生产服务器重定向到测试服务器。为此,我rewriteUrl
以下列方式使用 a:
public class Main {
public static void main(String[] args) {
BrowserMobProxyServer server = new BrowserMobProxyServer();
server.setTrustAllServers(true);
server.start(8888);
server.rewriteUrl("(https?://)init.mycompany.com(.*)","$1platform-sandbox.mycompany.com$2//");
if (server.isStarted()) {
System.out.println("Server started on " + server.getClientBindAddress() + ":" + server.getPort());
}
server.addRequestFilter(new RequestFilter() {
@Override
public HttpResponse filterRequest(io.netty.handler.codec.http.HttpRequest httpRequest, HttpMessageContents httpMessageContents, HttpMessageInfo httpMessageInfo) {
System.out.println("REQUEST");
System.out.println("Original: " + httpMessageInfo.getOriginalUrl());
System.out.println("Current: " + httpMessageInfo.getUrl());
return null;
}
});
server.addResponseFilter(new ResponseFilter() {
@Override
public void filterResponse(HttpResponse httpResponse, HttpMessageContents httpMessageContents, HttpMessageInfo httpMessageInfo) {
System.out.println("RESPONSE");
System.out.println("Original: " + httpMessageInfo.getOriginalUrl());
System.out.println("Current: " + httpMessageInfo.getUrl());
if (httpMessageInfo.getOriginalUrl() != httpMessageInfo.getUrl()) {
System.out.printf("DIFFERENT!!!!");
}
}
});
server.newHar("test");
while (true) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
你会注意到我取得了部分成功:
- 最后添加了两个
//
符号(这样做是为了测试)。 - 但是,
init
不会被替换platform-sandbox
要求
原文:https ://init.mycompany.com
当前:https ://init.mycompany.com
要求
原文:https ://init.mycompany.com/sdk/v6.4.6?applicationKey=42a8c1f5
当前:https ://init.mycompany.com/sdk/v6.4.6?applicationKey=42a8c1f5
回复
原文:https ://init.mycompany.com/sdk/v6.4.6?applicationKey=42a8c1f5
当前:https ://init.mycompany.com/sdk/v6.4.6?applicationKey=42a8c1f5//