本文整理汇总了Java中org.littleshoot.proxy.HttpFiltersSourceAdapter类的典型用法代码示例。如果您正苦于以下问题:Java HttpFiltersSourceAdapter类的具体用法?Java HttpFiltersSourceAdapter怎么用?Java HttpFiltersSourceAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpFiltersSourceAdapter类属于org.littleshoot.proxy包,在下文中一共展示了HttpFiltersSourceAdapter类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHttpFiltersSourceAdapter
import org.littleshoot.proxy.HttpFiltersSourceAdapter; //导入依赖的package包/类
private HttpFiltersSourceAdapter createHttpFiltersSourceAdapter() {
return new HttpFiltersSourceAdapter() {
@Override
public HttpFilters filterRequest(HttpRequest originalRequest) {
if (toRecord) {
return new ProxyEaterFilter(storage, originalRequest);
} else {
return new ProxyRegurgitatorFilter(storage, originalRequest);
}
}
//*
// Notice that the limit might give some trouble. Consider increasing significantly,
// _or_ handle chunks
@Override
public int getMaximumRequestBufferSizeInBytes() {
return 10 * 1024 * 1024;
}
@Override
public int getMaximumResponseBufferSizeInBytes() {
return 10 * 1024 * 1024;
}
//*/
};
}
示例2: start
import org.littleshoot.proxy.HttpFiltersSourceAdapter; //导入依赖的package包/类
public HttpProxyServer start() {
return DefaultHttpProxyServer.bootstrap()
.withAddress(new InetSocketAddress(host, port))
.withFiltersSource(new HttpFiltersSourceAdapter() {
@Override
public HttpFilters filterRequest(HttpRequest originalRequest) {
return new HttpFiltersAdapter(originalRequest) {
final String mockedAddress = mockServer + ":" + mockPort;
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
final HttpRequest request = (HttpRequest) httpObject;
if (request.getUri().contains("google")) {
request.setUri(mockedAddress);
}
super.clientToProxyRequest(request);
return null;
}
};
}
}).start();
}
示例3: start
import org.littleshoot.proxy.HttpFiltersSourceAdapter; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void start() {
List<Handler<HttpObject>> httpHandlerList = (List<Handler<HttpObject>>) getHandlerList();
DefaultHttpProxyServer.bootstrap()
.withPort(port).withFiltersSource(new HttpFiltersSourceAdapter() {
@Override
public HttpFilters filterRequest(HttpRequest originalRequest) {
return new HttpFiltersAdapter(originalRequest) {
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
httpHandlerList.forEach(httpObjectHandler -> httpObjectHandler.client2Proxy(httpObject));
return null;
}
};
}
}).start();
}
示例4: startProxy
import org.littleshoot.proxy.HttpFiltersSourceAdapter; //导入依赖的package包/类
/**
* Runs a proxy server counting requests
* @param authenticating true if the proxy should require authentication
* @throws Exception if an error occurred
*/
private void startProxy(boolean authenticating) throws Exception {
proxyPort = findPort();
HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer.bootstrap()
.withPort(proxyPort)
.withFiltersSource(new HttpFiltersSourceAdapter() {
public HttpFilters filterRequest(HttpRequest originalRequest,
ChannelHandlerContext ctx) {
return new HttpFiltersAdapter(originalRequest) {
@Override
public void proxyToServerRequestSent() {
proxyCounter++;
}
};
}
});
if (authenticating) {
bootstrap = bootstrap.withProxyAuthenticator(new ProxyAuthenticator() {
@Override
public boolean authenticate(String userName, String password) {
return PROXY_USERNAME.equals(userName) &&
PROXY_PASSWORD.equals(password);
}
@Override
public String getRealm() {
return "gradle-download-task";
}
});
}
proxy = bootstrap.start();
}