Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When compression is enabled via a predicate the response body is not compressed #411

Closed
wilkinsona opened this issue Aug 10, 2018 · 1 comment
Labels
type/bug A general bug
Milestone

Comments

@wilkinsona
Copy link

wilkinsona commented Aug 10, 2018

Expected behavior

The response body is compressed when the headers state that it is.

Actual behavior

The response body is not compressed.

Steps to reproduce

Apply the following diff to 0.7.x:

diff --git a/src/test/java/reactor/ipc/netty/http/server/HttpSendFileTests.java b/src/test/java/reactor/ipc/netty/http/server/HttpSendFileTests.java
index 87114cd..8dff809 100644
--- a/src/test/java/reactor/ipc/netty/http/server/HttpSendFileTests.java
+++ b/src/test/java/reactor/ipc/netty/http/server/HttpSendFileTests.java
@@ -115,6 +115,20 @@ public class HttpSendFileTests {
                }
        }

+       @Test
+       public void sendZipFileCompressionPredicate() throws IOException {
+               Path path = Files.createTempFile(null, ".zip");
+               Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING);
+               path.toFile().deleteOnExit();
+
+               try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) {
+                       Path fromZipFile = zipFs.getPath("/largeFile.txt");
+                       long fileSize = Files.size(fromZipFile);
+
+                       assertSendFile(out -> out.sendFile(fromZipFile, 0, fileSize), true);
+               }
+       }
+
        private void assertSendFile(Function<HttpServerResponse, NettyOutbound> fn) {
                assertSendFile(fn, false);
        }
@@ -130,7 +144,7 @@ public class HttpSendFileTests {

        private void assertSendFile(Function<HttpServerResponse, NettyOutbound> fn, boolean compression, Consumer<String> bodyAssertion) {
                NettyContext context =
-                               HttpServer.create(opt -> customizeServerOptions(opt.host("localhost")))
+                               HttpServer.create(opt -> customizeServerOptions(opt.host("localhost").compression((req, resp) -> true)))
                                          .newHandler((req, resp) -> fn.apply(resp))
                                          .block();

The intent of the new test is to use the predicate that's used to configure the server options to dictate whether or not the response is compressed. If you run it, it should fail like this:

reactor.ipc.netty.http.server.HttpsSendFileTests > sendZipFileCompressionPredicate FAILED
    io.netty.handler.codec.compression.DecompressionException: Input is not in the GZIP format

Alternatively, there's a less minimal example here.

Reactor Netty version

0.7.8.RELEASE

JVM version (e.g. java -version)

java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

OS version (e.g. uname -a)

macOS

@smaldini smaldini added this to the 0.7.x Maintenance Backlog milestone Aug 14, 2018
@smaldini smaldini added the type/bug A general bug label Aug 14, 2018
@violetagg violetagg modified the milestones: 0.7.x Maintenance Backlog, 0.7.9.RELEASE Aug 16, 2018
violetagg added a commit that referenced this issue Aug 16, 2018
Compression predicate has to be applied before sendFile invocation
because when we have compression in place we cannot use send file
with zero copy.
violetagg added a commit that referenced this issue Aug 16, 2018
Compression predicate has to be applied before sendFile invocation
because when there is a compression in place, send file with zero copy
cannot be used.
@violetagg
Copy link
Member

Closed #411 via caa1adf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants