use of java.util.zip.GZIPInputStream in project dropwizard by dropwizard.
the class JerseyClientIntegrationTest method checkBody.
private void checkBody(HttpExchange httpExchange, boolean gzip) throws IOException {
assertThat(httpExchange.getRequestHeaders().get(HttpHeaders.CONTENT_TYPE)).containsExactly(APPLICATION_JSON);
InputStream requestBody = gzip ? new GZIPInputStream(httpExchange.getRequestBody()) : httpExchange.getRequestBody();
String body = CharStreams.toString(new InputStreamReader(requestBody, StandardCharsets.UTF_8));
assertThat(JSON_MAPPER.readTree(body)).isEqualTo(JSON_MAPPER.createObjectNode().put("email", "john@doe.me").put("name", "John Doe"));
}
use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.
the class GzipHandlerTest method testGzipNotMicroChunked.
@Test
public void testGzipNotMicroChunked() throws Exception {
// generated and parsed test
HttpTester.Request request = HttpTester.newRequest();
HttpTester.Response response;
request.setMethod("GET");
request.setURI("/ctx/microchunked");
request.setVersion("HTTP/1.1");
request.setHeader("Host", "tester");
request.setHeader("Accept-Encoding", "gzip");
ByteBuffer rawresponse = _connector.getResponse(request.generate());
// System.err.println(BufferUtil.toUTF8String(rawresponse));
response = HttpTester.parseResponse(rawresponse);
assertThat(response.getStatus(), is(200));
assertThat(response.get("Transfer-Encoding"), containsString("chunked"));
assertThat(response.get("Content-Encoding"), containsString("gzip"));
assertThat(response.get("Vary"), is("Accept-Encoding"));
InputStream testIn = new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes()));
ByteArrayOutputStream testOut = new ByteArrayOutputStream();
IO.copy(testIn, testOut);
assertEquals(__micro, testOut.toString("UTF8"));
}
use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.
the class GzipHandlerTest method testGzipHandler.
@Test
public void testGzipHandler() throws Exception {
// generated and parsed test
HttpTester.Request request = HttpTester.newRequest();
HttpTester.Response response;
request.setMethod("GET");
request.setURI("/ctx/content?vary=Accept-Encoding,Other");
request.setVersion("HTTP/1.0");
request.setHeader("Host", "tester");
request.setHeader("accept-encoding", "gzip");
response = HttpTester.parseResponse(_connector.getResponses(request.generate()));
assertThat(response.getStatus(), is(200));
assertThat(response.get("Content-Encoding"), Matchers.equalToIgnoringCase("gzip"));
assertThat(response.get("ETag"), is(__contentETagGzip));
assertThat(response.getCSV("Vary", false), Matchers.contains("Accept-Encoding", "Other"));
InputStream testIn = new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes()));
ByteArrayOutputStream testOut = new ByteArrayOutputStream();
IO.copy(testIn, testOut);
assertEquals(__content, testOut.toString("UTF8"));
}
use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.
the class GzipHandlerTest method testForwardGzipHandler.
@Test
public void testForwardGzipHandler() throws Exception {
// generated and parsed test
HttpTester.Request request = HttpTester.newRequest();
HttpTester.Response response;
request.setMethod("GET");
request.setVersion("HTTP/1.0");
request.setHeader("Host", "tester");
request.setHeader("accept-encoding", "gzip");
request.setURI("/ctx/forward");
response = HttpTester.parseResponse(_connector.getResponses(request.generate()));
assertThat(response.getStatus(), is(200));
assertThat(response.get("Content-Encoding"), Matchers.equalToIgnoringCase("gzip"));
assertThat(response.get("ETag"), is(__contentETagGzip));
assertThat(response.get("Vary"), is("Accept-Encoding"));
InputStream testIn = new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes()));
ByteArrayOutputStream testOut = new ByteArrayOutputStream();
IO.copy(testIn, testOut);
assertEquals(__content, testOut.toString("UTF8"));
}
use of java.util.zip.GZIPInputStream in project jetty.project by eclipse.
the class GZIPContentDecoderTest method testStreamNoBlocks.
@Test
public void testStreamNoBlocks() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.close();
byte[] bytes = baos.toByteArray();
GZIPInputStream input = new GZIPInputStream(new ByteArrayInputStream(bytes), 1);
int read = input.read();
assertEquals(-1, read);
}
Aggregations