2

I followed the simple example shown GitHub:LittleProxy and have added the following in clientToProxyRequest(HttpObject httpObject) Method.

public HttpResponse clientToProxyRequest(HttpObject httpObject)
{
  if(httpObject instanceof DefaultHttpRequest)
  {
    DefaultHttpRequest httpRequest = (DefaultHttpRequest)httpObject;
    logger.info(httpRequest.getUri());          
    logger.info(httpRequest.toString());

    // How to access the POST Body data?            
    HttpPostRequestDecoder d = new HttpPostRequestDecoder(httpRequest);
    d.getBodyHttpDatas();   //NotEnoughDataDecoderException
  }
  return null;
} 

The logger report this, IMO only these two header are relevant here. It's a POST request and there is content ...

POST http://www.... HTTP/1.1
Content-Length: 522

Looking into Netty API documentation the HttpPostRequestDecoder seems to be promising, but I get a NotEnoughDataDecoderException. In Netty JavaDoc this is written, but I do not know how to offer data?

This getMethod returns a List of all HttpDatas from body. If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.

In fact I'm also unsure if this is the right approach to get the POST data in the proxy.

Thor
  • 6,607
  • 13
  • 62
  • 96

1 Answers1

2

try to add this in your HttpFiltersSourceAdapter to aviod NotEnoughDataDecoderException:

@Override
public int getMaximumRequestBufferSizeInBytes() {
    return 1048576; 
}

1048576 here is the maximum length of the aggregated content. See POSTing data to netty with Apache HttpClient.

This will enables decompression and aggregation of content, see the source code in org.littleshoot.proxy.impl.ClientToProxyConnection:

// Enable aggregation for filtering if necessary
int numberOfBytesToBuffer = proxyServer.getFiltersSource()
            .getMaximumRequestBufferSizeInBytes();
if (numberOfBytesToBuffer > 0) {
    aggregateContentForFiltering(pipeline, numberOfBytesToBuffer);
}
Community
  • 1
  • 1
Scott Jin
  • 21
  • 2