Skip to content

Commit

Permalink
consistent gzip test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Maldini authored and smaldini committed Feb 27, 2018
1 parent 95b22e0 commit d487c3c
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/test/java/reactor/ipc/netty/http/client/HttpClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -563,51 +563,54 @@ public void prematureCancel() throws Exception {

@Test
public void gzip() {

String content = "HELLO WORLD";

NettyContext c = HttpServer.create(opts -> opts.compression(true).port(0))
.newHandler((req, res) -> res.sendString(Mono.just(content)))
.block();


//verify gzip is negotiated (when no decoder)
StepVerifier.create(
HttpClient.create()
.get("http://www.httpwatch.com", req -> req
HttpClient.create(c.address().getPort())
.get("/", req -> req
.followRedirect()
.addHeader("Accept-Encoding", "gzip")
.addHeader("Accept-Encoding", "deflate")
)
.flatMap(r -> r.receive().asString()
.elementAt(0)
.map(s -> s.substring(0, Math.min(s.length() -1, 100)))
.flatMap(r -> r.receive().aggregate().asString()
.zipWith(Mono.just(r.responseHeaders().get("Content-Encoding", "")))
.zipWith(Mono.just(r)))
)
.expectNextMatches(tuple -> {
tuple.getT2().dispose();
String content = tuple.getT1().getT1();
return !content.contains("<html>") && !content.contains("<head>")
return !tuple.getT1().getT1().equals(content)
&& "gzip".equals(tuple.getT1().getT2());
})
.expectComplete()
.verify();

//verify decoder does its job and removes the header
StepVerifier.create(
HttpClient.create()
.get("http://www.httpwatch.com", req -> {
HttpClient.create(c.address().getPort())
.get("/", req -> {
req.context().addHandlerFirst("gzipDecompressor", new HttpContentDecompressor());
return req.followRedirect()
.addHeader("Accept-Encoding", "gzip")
.addHeader("Accept-Encoding", "deflate");
})
.flatMap(r -> r.receive().asString().elementAt(0)
.map(s -> s.substring(0, Math.min(s.length() -1, 100)))
.flatMap(r -> r.receive().aggregate().asString()
.zipWith(Mono.just(r.responseHeaders().get("Content-Encoding", "")))
.zipWith(Mono.just(r)))
)
.expectNextMatches(tuple -> {
tuple.getT2().dispose();
String content = tuple.getT1().getT1();
return content.contains("<html>") && content.contains("<head>")
return tuple.getT1().getT1().equals(content)
&& "".equals(tuple.getT1().getT2());
})
.expectComplete()
.verify();

c.dispose();
}

@Test
Expand Down

0 comments on commit d487c3c

Please sign in to comment.