Created
October 31, 2013 19:33
-
-
Save jkeys089/7255468 to your computer and use it in GitHub Desktop.
Vert.x HttpClient test -- fixed response body with compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void testResponseBodyWriteFixedString() { | |
final String body = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; | |
final Buffer bodyBuff = new Buffer(body); | |
AsyncResultHandler<HttpServer> handler = new AsyncResultHandler<HttpServer>() { | |
@Override | |
public void handle(AsyncResult<HttpServer> ar) { | |
tu.azzert(ar.succeeded()); | |
final HttpClientRequest req = getRequest(true, "GET", "some-uri", new Handler<HttpClientResponse>() { | |
public void handle(HttpClientResponse resp) { | |
tu.checkThread(); | |
if (compression()) { | |
tu.azzert("gzip".equalsIgnoreCase(resp.headers().get("Content-Encoding"))); | |
} | |
resp.bodyHandler(new Handler<Buffer>() { | |
public void handle(Buffer buff) { | |
tu.azzert(TestUtils.buffersEqual(bodyBuff, buff)); | |
tu.testComplete(); | |
} | |
}); | |
} | |
}); | |
if (compression()) { | |
req.putHeader("Accept-Encoding", "gzip"); | |
} | |
req.end(); | |
} | |
}; | |
startServer(new Handler<HttpServerRequest>() { | |
public void handle(final HttpServerRequest req) { | |
tu.checkThread(); | |
req.response().setChunked(true); | |
req.response().write(body); | |
req.response().end(); | |
} | |
}, handler); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment