/** * @return if this encoding has a compressor. Generally, speaking, this is false * for ANY (*). */ public boolean hasCompressor() { return getCompressor() != null; } }
byte[] inflated = encoding.getCompressor().inflate(res.getEntity().asInputStream()); Map<String, String> headers = new HashMap<String, String>(res.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING);
byte[] decompressedContent = encoding.getCompressor().inflate(req.getEntity().asInputStream()); Map<String, String> headers = new HashMap<String, String>(req.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING);
@Test(dataProvider = "requestCompressionData") public void testRequestCompressionRules(CompressionConfig requestCompressionConfig, CompressionOption requestCompressionOverride, boolean headerShouldBePresent) throws CompressionException, URISyntaxException { ClientCompressionFilter clientCompressionFilter = new ClientCompressionFilter(EncodingType.SNAPPY.getHttpName(), requestCompressionConfig, ACCEPT_COMPRESSIONS, new CompressionConfig(Integer.MAX_VALUE), Collections.<String>emptyList()); // The entity should be compressible for this test. int original = 100; byte[] entity = new byte[original]; Arrays.fill(entity, (byte)'A'); RestRequest restRequest = new RestRequestBuilder(new URI(URI)).setMethod(RestMethod.POST).setEntity(entity).build(); int compressed = EncodingType.SNAPPY.getCompressor().deflate(new ByteArrayInputStream(entity)).length; RequestContext context = new RequestContext(); context.putLocalAttr(R2Constants.REQUEST_COMPRESSION_OVERRIDE, requestCompressionOverride); int entityLength = headerShouldBePresent ? compressed : original; String expectedContentEncoding = headerShouldBePresent ? EncodingType.SNAPPY.getHttpName() : null; clientCompressionFilter.onRestRequest(restRequest, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.CONTENT_ENCODING, expectedContentEncoding, entityLength)); }
@Test(dataProvider = "headersData") public void testResponseCompressionRules(String acceptEncoding, int compressionThreshold, EncodingType expectedContentEncoding) throws CompressionException, URISyntaxException { ServerCompressionFilter serverCompressionFilter = new ServerCompressionFilter(ACCEPT_COMPRESSIONS); RequestContext context = new RequestContext(); context.putLocalAttr(HttpConstants.ACCEPT_ENCODING, acceptEncoding); context.putLocalAttr(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD, compressionThreshold); int originalLength = 100; byte[] entity = new byte[originalLength]; Arrays.fill(entity, (byte) 'A'); int compressedLength = (expectedContentEncoding == null) ? originalLength : expectedContentEncoding.getCompressor().deflate(new ByteArrayInputStream(entity)).length; String expectedContentEncodingName = (expectedContentEncoding == null) ? null : expectedContentEncoding.getHttpName(); RestResponse restResponse = new RestResponseBuilder().setEntity(entity).build(); serverCompressionFilter.onRestResponse(restResponse, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.CONTENT_ENCODING, expectedContentEncodingName, compressedLength)); } }
.build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(entity)))); int compressed = EncodingType.GZIP.getCompressor().deflate(new ByteArrayInputStream(entity)).length; RequestContext context = new RequestContext(); if (operation != null)
.build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(entity)))); int compressed = EncodingType.GZIP.getCompressor().deflate(new ByteArrayInputStream(entity)).length; RequestContext context = new RequestContext(); if (operation != null)
)) Compressor compressor = _requestContentEncoding.getCompressor(); byte[] compressed = compressor.deflate(req.getEntity().asInputStream());
res.getEntity().length() > (Integer) requestContext.getLocalAttr(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD)) Compressor compressor = selectedEncoding.getCompressor(); byte[] compressed = compressor.deflate(res.getEntity().asInputStream());
/** * @return if this encoding has a compressor. Generally, speaking, this is false * for ANY (*). */ public boolean hasCompressor() { return getCompressor() != null; } }
byte[] inflated = encoding.getCompressor().inflate(res.getEntity().asInputStream()); Map<String, String> headers = new HashMap<String, String>(res.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING);
byte[] decompressedContent = encoding.getCompressor().inflate(req.getEntity().asInputStream()); Map<String, String> headers = new HashMap<String, String>(req.getHeaders()); headers.remove(HttpConstants.CONTENT_ENCODING);
)) Compressor compressor = _requestContentEncoding.getCompressor(); byte[] compressed = compressor.deflate(req.getEntity().asInputStream());
res.getEntity().length() > (Integer) requestContext.getLocalAttr(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD)) Compressor compressor = selectedEncoding.getCompressor(); byte[] compressed = compressor.deflate(res.getEntity().asInputStream());