1

I am using below code where I have added netty's HttpContentCompressor to compress the response coming out from my server. How ever when my server returns a response i.e. a string "test" HttpContentCompressor is not encoding it and returning it as test�.

I am already sending accept-encoding: zgip in the request! Have anyone faced this issue?

    public void customize(NettyReactiveWebServerFactory factory) {
        // Set Port and enable HTTP/2
            factory.setPort(httpPort);
        // HTTP 2.0 settings
            if (isHTTP2Enabled) {
                factory.addServerCustomizers(builder -> builder
                    .tcpConfiguration(tcpServer -> 
    tcpServer.doOnConnection((java.util.function.Consumer<Connection>) 
    connection -> {
                          
           connection.addHandler(connectionTerminator);
            connection.addHandlerLast("decompressor",
                                 new HttpContentDecompressor());
            connection.addHandlerLast("compress",
 new HttpContentCompressor(StandardCompressionOptions.gzip()));
            connection.channel().pipeline();
            }))
.protocol(HttpProtocol.H2C, HttpProtocol.HTTP11).http2Settings(http2SettingsBuilder -> {
                         http2SettingsBuilder.initialWindowSize(serverInitialWindowSize);
                        http2SettingsBuilder.maxConcurrentStreams(serverMaxConcurrentStreams);
                    }));
    } 

While putting a debug point in netty JdkZlibEncoder code I can see that code is returning without doing actual encoding:enter image description here

Vaibhav
  • 169
  • 6
  • 1
    You might have forgotten to add the code in your question. – Marcelo Paco Apr 04 '23 at 17:53
  • Thanks Marcelo, I have added it now! – Vaibhav Apr 04 '23 at 18:04
  • 1
    Why do you need to do this by yourself and not just configure the server to compress? https://projectreactor.io/docs/netty/release/reference/index.html#_compression – Violeta Georgieva Apr 04 '23 at 19:48
  • Thanks much Violeta I am doing it now as the way document (you shared) suggests and seems netty has started compressing , will test this thoroughly , just one think in this documentation it only talks about compression but not decompression, Am I missing something? – Vaibhav Apr 05 '23 at 04:37
  • 1
    decompression on the server is not supported – Violeta Georgieva Apr 05 '23 at 05:24
  • Hi @VioletaGeorgieva I was further looking at how netty server can be customized to support this decompression and could found example below as mentioned here :https://www.tabnine.com/code/java/classes/io.netty.handler.codec.http.HttpContentDecompressor 'pipeline.addLast(new HttpContentDecompressor());' is it recommended way to do the response decompression? Any knowledge or any documentation do you have around it? – Vaibhav Apr 17 '23 at 15:50
  • My comment above was for **request** decompression on the server - it is not supported. While **response** decompression on the client is supported. – Violeta Georgieva Apr 21 '23 at 16:07
  • Sorry for my typo, I also wanted to talk about request decompression , seems people are able to do it on netty server by 'pipeline.addLast(new HttpContentDecompressor()) I could just find below documentation for it, these are useful but does not give example about how to use these. https://javadoc.io/static/io.netty/netty/3.9.2.Final/org/jboss/netty/handler/codec/http/HttpContentDecompressor.html https://javadoc.io/static/io.netty/netty/3.9.2.Final/org/jboss/netty/handler/codec/http/HttpContentDecoder.html – Vaibhav Apr 22 '23 at 00:13

0 Answers0