Search code examples
javanettylittle-proxy

Add channel handler for gzip deflate in netty proxy


In the following file: https://github.com/adamfisk/LittleProxy/blob/master/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java

I need to add a 'channel handler' which will deflate gzipped content. I have no idea how to do this having no netty knowledge. Can somebody give me a point in the right direction?


Solution

  • As others pointed out, your code is a bit too long and it makes the life of people on this website a bit more difficult, but I think I can help you a little bit.

    To give a small explanation about netty, each request that you receive goes through a pipeline of handlers, and each requests has its own pipeline associated with.

    So it is in the method initiating your pipeline that you should add a handler for decompression, in your case:

    initChannelPipeline(ChannelPipeline pipeline, HttpRequest httpRequest)
    

    The handler you are looking for is either HttpContentDecompressor or HttpContentCompressor whether you are trying to uncompress gzipped data or compress it into gzip (it is unclear as you say you would like to deflate gzip content. You should say inflate it if is gzipped or deflate it if is not compressed. Think of it as a balloon. When inflated, it takes a lot more space).

    You should pay attention to the order in which you add your handlers in the pipeline.

    See Channel pipeline doc for more explanation.