You need to override this two methods in a HttpFiltersSourceAdapter. Return a non-zero buffer size. LittleProxy will automatically aggregate httpRequest and httpContent and wrapped into an AggregatedFullHttpRequest, which allow to cast to httpContent.
@Override
public int getMaximumRequestBufferSizeInBytes() {
return 1024 * 1024;
}
@Override
public int getMaximumResponseBufferSizeInBytes() {
return 1024 * 1024 * 2;
}
Then you can clone and read content in HTTP package:
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;
}