org.springframework.boot.web.server.Compression Java Examples

The following examples show how to use org.springframework.boot.web.server.Compression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArmeriaReactiveWebServerFactoryTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Test
void shouldReturnCompressedResponse() {
    final ArmeriaReactiveWebServerFactory factory = factory();
    final Compression compression = new Compression();
    compression.setEnabled(true);
    compression.setMinResponseSize(DataSize.ofBytes(1));
    compression.setMimeTypes(new String[] { "text/plain" });
    compression.setExcludedUserAgents(new String[] { "unknown-agent/[0-9]+\\.[0-9]+\\.[0-9]+$" });
    factory.setCompression(compression);
    runEchoServer(factory, server -> {
        final AggregatedHttpResponse res = sendPostRequest(httpClient(server));
        assertThat(res.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.OK);
        assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING)).isEqualTo("gzip");
        assertThat(res.contentUtf8()).isNotEqualTo("hello");
    });
}
 
Example #2
Source File: CompressionCustomizer.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public HttpServerOptions apply(HttpServerOptions options) {
    Compression compression = factory.getCompression();

    if (compression != null) {
        options.setCompressionSupported(compression.getEnabled());
    }

    return options;
}
 
Example #3
Source File: ArmeriaReactiveWebServerFactoryTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void shouldReturnNonCompressedResponse_dueToContentType() {
    final ArmeriaReactiveWebServerFactory factory = factory();
    final Compression compression = new Compression();
    compression.setEnabled(true);
    compression.setMinResponseSize(DataSize.ofBytes(1));
    compression.setMimeTypes(new String[] { "text/html" });
    factory.setCompression(compression);
    runEchoServer(factory, server -> {
        final AggregatedHttpResponse res = sendPostRequest(httpClient(server));
        validateEchoResponse(res);
        assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING)).isNull();
    });
}
 
Example #4
Source File: ArmeriaReactiveWebServerFactoryTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void shouldReturnNonCompressedResponse_dueToUserAgent() {
    final ArmeriaReactiveWebServerFactory factory = factory();
    final Compression compression = new Compression();
    compression.setEnabled(true);
    compression.setMinResponseSize(DataSize.ofBytes(1));
    compression.setExcludedUserAgents(new String[] { "test-agent/[0-9]+\\.[0-9]+\\.[0-9]+$" });
    factory.setCompression(compression);
    runEchoServer(factory, server -> {
        final AggregatedHttpResponse res = sendPostRequest(httpClient(server));
        validateEchoResponse(res);
        assertThat(res.headers().get(HttpHeaderNames.CONTENT_ENCODING)).isNull();
    });
}
 
Example #5
Source File: CompressionCustomizer.java    From spring-boot-rsocket with Apache License 2.0 4 votes vote down vote up
CompressionCustomizer(Compression compression) {
	this.compression = compression;
}
 
Example #6
Source File: ArmeriaReactiveWebServerFactory.java    From armeria with Apache License 2.0 4 votes vote down vote up
private void configureArmeriaService(ServerBuilder sb, ArmeriaSettings settings) {
    final MeterIdPrefixFunctionFactory meterIdPrefixFunctionFactory =
            settings.isEnableMetrics() ? firstNonNull(findBean(MeterIdPrefixFunctionFactory.class),
                                                      MeterIdPrefixFunctionFactory.ofDefault())
                                       : null;

    configurePorts(sb, settings.getPorts());
    final DocServiceBuilder docServiceBuilder = DocService.builder();
    configureThriftServices(sb,
                            docServiceBuilder,
                            findBeans(ThriftServiceRegistrationBean.class),
                            meterIdPrefixFunctionFactory,
                            settings.getDocsPath());
    configureGrpcServices(sb,
                          docServiceBuilder,
                          findBeans(GrpcServiceRegistrationBean.class),
                          meterIdPrefixFunctionFactory,
                          settings.getDocsPath());
    configureHttpServices(sb,
                          findBeans(HttpServiceRegistrationBean.class),
                          meterIdPrefixFunctionFactory);
    configureAnnotatedServices(sb,
                               docServiceBuilder,
                               findBeans(AnnotatedServiceRegistrationBean.class),
                               meterIdPrefixFunctionFactory,
                               settings.getDocsPath());
    configureServerWithArmeriaSettings(sb, settings,
                                       firstNonNull(findBean(MeterRegistry.class), Metrics.globalRegistry),
                                       findBeans(HealthChecker.class));
    if (settings.getSsl() != null) {
        configureTls(sb, settings.getSsl());
    }

    final ArmeriaSettings.Compression compression = settings.getCompression();
    if (compression != null && compression.isEnabled()) {
        final long parsed = parseDataSize(compression.getMinResponseSize());
        sb.decorator(contentEncodingDecorator(compression.getMimeTypes(),
                                              compression.getExcludedUserAgents(),
                                              Ints.saturatedCast(parsed)));
    }

    if (!Strings.isNullOrEmpty(settings.getDocsPath())) {
        sb.serviceUnder(settings.getDocsPath(), docServiceBuilder.build());
    }
}