I have been playing with Littleproxy and found it easy to modify responses, but can't get any good example of modifying request parameters.
On the net I have found only one example, modifying post data. But cannot make it work.
Would you have an example explaining how we can get the request parameters and modify them.
I have this:
public HttpResponse proxyToServerRequest(HttpObject httpObject) {
if(httpObject instanceof FullHttpRequest){
FullHttpRequest request = (FullHttpRequest) httpObject;
if(request.getMethod() == HttpMethod.POST
&& request.getUri().contains("/post")){
CompositeByteBuf contentBuf = (CompositeByteBuf) request.content();
String contentStr = contentBuf.toString(CharsetUtil.UTF_8);
System.out.println("Post content for " + request.getUri() + " : " + contentStr);
String newBody = contentStr.replace("e", "ei");
ByteBuf bodyContent = Unpooled.copiedBuffer(newBody, CharsetUtil.UTF_8);
contentBuf.clear().writeBytes(bodyContent);
HttpHeaders.setContentLength(request, newBody.length());
}
}
return null;
}
Do you know any other good example?