1

I have tried various flavors and all are giving giberish results. But the response on the browser looks fine. (clean json String)

    FullHttpResponse response = (FullHttpResponse) msg;
    byte[] bytes = new byte[response.content().readableBytes()];
    response.content().readBytes(bytes);
    String result = new String(bytes);

The other one I tried as suggested here is

response.content().toString(CharsetUtil.UTF_8);

Both are gibberish like this

enter image description here

P.S: I use HttpObjectAggregator and HttpServerCodec in pipeline

brain storm
  • 30,124
  • 69
  • 225
  • 393

1 Answers1

1

You are most likely looking at compressed data, since you are dealing with instances of FullHttpResponse, and most servers these days use compression, it is highly likely that your data is compressed.

To see the compression algorithm behind the compression, you should look into response.headers().get(HttpHeaders.Names.CONTENT_ENCODING)

This can return a combination of differend values (separated by , in the case of multiple recordings):

  • gzip: The data is compressed using GZip
  • `deflate: The data is compressed using deflate
  • identity: No compression has taken place
  • br: The data is compressed using brotli

One advantage of using FullHttpResponse is that you don't have to worry about the transfer encoding in use, as it handles that for you.

Ferrybig
  • 18,194
  • 6
  • 57
  • 79
  • can you give your thoughts on this? https://stackoverflow.com/questions/55600097/new-handlers-not-created-for-each-requests-in-netty – brain storm Apr 09 '19 at 19:37
  • When I try to get the compression algorithm I only get null as a response, even thou I know that is not true. Using littleproxy-mitm. – Mr Krisey Nov 16 '20 at 21:05
  • 1
    @MrKrisey Could you print the transfer encoding, some combinations of proxies and other things use that header – Ferrybig Nov 17 '20 at 23:24
  • Thanks. That solved the problem. Another question: I use FullHttpResponse but the content is still compressed. Was that not what you meant with an advantage with FullHttpResponse? – Mr Krisey Nov 18 '20 at 17:22