1

I'm working with Vertx 3.5.3 in a REST application that also provides static files using the Vertx Web StaticHandler handler.

I'm using own Vertx HttpServer with this configuration:

HttpServerOptions httpServerOptions = new HttpServerOptions()
            .setCompressionSupported(true)
            .setCompressionLevel(7)
            .setTcpKeepAlive(true);

HttpServer httpServer = vertx.createHttpServer(httpServerOptions);
httpServer.requestStream().toObservable().subscribe(router::accept);

httpServer.listen(
            serverConfig.getPort(),
            serverConfig.getHost(),
            result -> {
                if (result.succeeded()) {
                    LOGGER.info("Server verticle is now up, listening on " 
                        + serverConfig.getHost() + ":" + serverConfig.getPort());
                } else {
                    LOGGER.error("Error starting verticle on " + serverConfig.getHost() + ":" + serverConfig.getPort(), result.cause());
                }
            });

And this is the static handler configuration in the Vertx router:

    // handler for static files
    router.route("/*")
            .handler(StaticHandler
                    .create()
                    .setAllowRootFileSystemAccess(false)
                    .setAlwaysAsyncFS(true)
                    .setCacheEntryTimeout(604800)
                    .setCachingEnabled(true)
                    .setDefaultContentEncoding("UTF-8")
                    .setDirectoryListing(false)
                    .setEnableFSTuning(true)
                    .setIncludeHidden(false)
                    .setIndexPage("index.html")
                    .setMaxAgeSeconds(604800)
                    .setSendVaryHeader(true));

That's the basic configuration.

My doubt is why when the compression (gzip) of the server is activated, it doesn't show the content-length header in the browser, but sends the header Transfer-Encoding: chunked. When I deactivate the compression (gzip) of the server, the server sends the content-length header with the filesize.

An imagen of the first case (javascript file):

Netty compression is activated

And an image of the second case (same javascript file):

Netty compression is deactivated

There is a way to send from server the content-length header when the compression (gzip) is active?

I found this PR in the Netty repo, so I assume Netty does allow this behavior and it's Vertx isn't sending the header.

Thanks.

Cristiam Mercado
  • 573
  • 12
  • 34
  • 1
    Gzip is a stream-encoding so switching to a chunked transfer is the natural thing to do (and it is absolutely legal and valid in HTTP.) Thus: is there any *concrete* problem that occurs in your application, or is this just curiosity? – mtj Aug 27 '18 at 05:36
  • 1
    @mtj I'm working on service workers in Chrome with application cache and the `Content-Length` column of file list is always zero, but when the server returns that header, the actual size appears in that column. I have doubts about whether that `Content-Length` column is relevant or not. – Cristiam Mercado Aug 27 '18 at 13:18
  • 3
    No, it isn't. Chunked mode is an alternative encoding which can be used if the length is not known in advance (due to streaming gzip or the like.) You can read up on it in wikipedia https://en.wikipedia.org/wiki/Chunked_transfer_encoding . Thus: as long as there is no technical problem with the client, you are facing a pure cosmetical issue. – mtj Aug 28 '18 at 04:32

0 Answers0