您需要在HttpFiltersSourceAdapter中重寫這兩個方法。返回一個非零的緩衝區大小。 LittleProxy會自動將httpRequest和httpContent聚合在一起幷包裝到一個AggregatedFullHttpRequest中,該AggregatedFullHttpRequest允許轉換爲httpContent。
@Override
public int getMaximumRequestBufferSizeInBytes() {
return 1024 * 1024;
}
@Override
public int getMaximumResponseBufferSizeInBytes() {
return 1024 * 1024 * 2;
}
然後你就可以克隆和讀取HTTP包內容:
String cloneAndExtractContent(HttpObject httpObject, Charset charset){
List<Byte> bytes = new ArrayList<Byte>();
HttpContent httpContent = (HttpContent) httpObject;
ByteBuf buf = httpContent.content();
byte[] buffer = new byte[buf.readableBytes()];
if(buf.readableBytes() > 0) {
int readerIndex = buf.readerIndex();
buf.getBytes(readerIndex, buffer);
}
for(byte b : buffer){
bytes.add(b);
}
return new String(Bytes.toArray(bytes), charset);
}
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
System.out.println("clientToProxyRequest - to -> "+getRequestUrl());
System.out.println(cloneAndExtractContent(httpObject, StandardCharsets.UTF_8));
return null;
}
@Override
public HttpObject serverToProxyResponse(HttpObject httpObject)
{
System.out.println("serverToProxyResponse <- from - "+getRequestUrl());
System.out.println(cloneAndExtractContent(httpObject, StandardCharsets.UTF_8));
return httpObject;
}
我想這是相當有關,而不是網狀到littleproxy。如何用'littleproxy'標記你的問題並召喚Adam Fisk? – trustin 2013-04-10 07:34:45