@Test public void default_constructor_works_as_expected() { // when SmartHttpContentDecompressor decompressor = new SmartHttpContentDecompressor(); // then assertThat(Whitebox.getInternalState(decompressor, "strict")).isEqualTo(false); }
@Override protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception { // We only allow decompression if the endpoint allows it. HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get(); Endpoint<?> endpoint = state.getEndpointForExecution(); if (endpointAllowsDecompression(endpoint, state)) { return super.newContentDecoder(contentEncoding); } // The endpoint does not allow decompression. Return null to indicate that this handler should not // auto-decompress this request's payload. return null; }
@DataProvider(value = { "GZIP", "X_GZIP", "DEFLATE", "X_DEFLATE", "CONTENT_ENCODING_THAT_DOES_NOT_REPRESENT_COMPRESSED_PAYLOAD", "ENDPOINT_DOES_NOT_WANT_DECOMPRESS", "NULL_ENDPOINT" }) @Test public void newContentDecoder_works_as_expected(NewContentDecoderScenario scenario) throws Exception { // given SmartHttpContentDecompressor decompressor = new SmartHttpContentDecompressor(); TestUtil.ChannelHandlerContextMocks mocks = TestUtil.mockChannelHandlerContext(); Whitebox.setInternalState(decompressor, "ctx", mocks.mockContext); ChannelMetadata channelMetadata = new ChannelMetadata(false); ChannelConfig channelConfigMock = mock(ChannelConfig.class); doReturn(scenario.endpoint).when(mocks.mockHttpProcessingState).getEndpointForExecution(); doReturn(channelMetadata).when(mocks.mockChannel).metadata(); doReturn(channelConfigMock).when(mocks.mockChannel).config(); // when EmbeddedChannel result = decompressor.newContentDecoder(scenario.contentEncoding); // then if (scenario.expectValidDecompressor) { assertThat(result).isNotNull(); } else { assertThat(result).isNull(); } }
@DataProvider(value = { "true", "false" }) @Test public void single_arg_constructor_works_as_expected(boolean strict) { // when SmartHttpContentDecompressor decompressor = new SmartHttpContentDecompressor(strict); // then assertThat(Whitebox.getInternalState(decompressor, "strict")).isEqualTo(strict); }
@Override protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception { // We only allow decompression if the endpoint allows it. HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get(); Endpoint<?> endpoint = state.getEndpointForExecution(); if (endpointAllowsDecompression(endpoint, state)) { return super.newContentDecoder(contentEncoding); } // The endpoint does not allow decompression. Return null to indicate that this handler should not // auto-decompress this request's payload. return null; }
p.addLast(SMART_HTTP_CONTENT_DECOMPRESSOR_HANDLER_NAME, new SmartHttpContentDecompressor());
p.addLast(SMART_HTTP_CONTENT_DECOMPRESSOR_HANDLER_NAME, new SmartHttpContentDecompressor());