Java littleproxy mitm: getting response body

Tags: , , ,



I am trying to use littleproxy-mitm to inspect traffic. I have access to the headers and can easily read them. However, I cant find the body of a response consitently. To see if I can get the body I am using this testing my app by visiting https://www.google.com/humans.txt, but the wanted body is no where to be found. But when I visit other sites like google, facebook and twitter I seem to get gibberish(encoded body gzip most prob) and sometimes html.

Here is the filter:

@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
        if(httpObject instanceof FullHttpResponse){
            System.out.println("FullHttpResponse ----------------------------------------");
            FullHttpResponse response = (FullHttpResponse) httpObject;
            CompositeByteBuf contentBuf = (CompositeByteBuf) response.content();

            String contentStr = contentBuf.toString(CharsetUtil.UTF_8);
            System.out.println(contentStr);
        }
        return httpObject;
    }

Any idea why I am unable to get body from https://www.google.com/humans.txt ?

Answer

To answer my own question.

This code snippet works and will print the whole response. But the reason I was not getting the body response is either the header “Modified-since..” or the “Cache-control: public”.



Source: stackoverflow