LittleProxy
Posted by Bruce Tsai
07/26/2016
LittleProxy 是一個高效能且輕量的 HTTP Proxy 類別庫,並以事件為基礎(Event Trigger)來處理 Proxy 中的請求與回應。若需要開發一個小型的 Proxy 或 Gateway 功能,LittleProxy 是一個不錯的選擇。
使用範例
<dependency>
<groupId>org.littleshoot</groupId>
<artifactId>littleproxy</artifactId>
<version>1.1.0</version>
</dependency>
HttpProxyServer server =
DefaultHttpProxyServer.bootstrap()
.withPort(8080)
.withFiltersSource(new HttpFiltersSourceAdapter() {
public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext ctx) {
return new HttpFiltersAdapter(originalRequest) {
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
// TODO: implement your filtering here
return null;
}
@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
// TODO: implement your filtering here
return httpObject;
}
};
}
})
.start();