ArmeriaConfigurationUtil { static void configureServer(ServerBuilder serverBuilder, ArmeriaSettings settings) { requireNonNull(serverBuilder, "serverBuilder"); requireNonNull(settings, "settings"); if (settings.getGracefulShutdownQuietPeriodMillis() >= 0 && settings.getGracefulShutdownTimeoutMillis() >= 0) { serverBuilder.gracefulShutdownTimeoutMillis(settings.getGracefulShutdownQuietPeriodMillis(), settings.getGracefulShutdownTimeoutMillis()); logger.debug("Set graceful shutdown timeout: quiet period {} ms, timeout {} ms", settings.getGracefulShutdownQuietPeriodMillis(), settings.getGracefulShutdownTimeoutMillis()); } if (settings.getMaxRequestLength() != null) { serverBuilder.maxRequestLength(settings.getMaxRequestLength()); } if (settings.getMaxNumConnections() != null) { serverBuilder.maxNumConnections(settings.getMaxNumConnections()); } if (!settings.isDateHeaderEnabled()) { serverBuilder.disableDateHeader(); } if (!settings.isServerHeaderEnabled()) { serverBuilder.disableServerHeader(); } if (settings.getDefaultHostname() != null) { serverBuilder.defaultHostname(settings.getDefaultHostname()); } if (settings.isVerboseResponses()) { serverBuilder.verboseResponses(true); } if (settings.getPorts().isEmpty()) { serverBuilder.port(new ServerPort(DEFAULT_PORT.getPort(), DEFAULT_PORT.getProtocols())); } else { configurePorts(serverBuilder, settings.getPorts()); } if (settings.getSsl() != null) { configureTls(serverBuilder, settings.getSsl()); } if (settings.getCompression() != null) { configureCompression(serverBuilder, settings.getCompression()); } if (settings.getHttp1() != null) { configureHttp1(serverBuilder, settings.getHttp1()); } if (settings.getHttp2() != null) { configureHttp2(serverBuilder, settings.getHttp2()); } if (settings.getProxy() != null) { configureProxy(serverBuilder, settings.getProxy()); } if (settings.getAccessLog() != null) { configureAccessLog(serverBuilder, settings.getAccessLog()); } } private  ArmeriaConfigurationUtil();   }
@Test void configureServer() throws Exception { final File yml = new File(resourceFilePath("armeria-settings.yaml")); final ArmeriaSettings armeriaSettings = configFactory.build(yml); armeriaSettings.setSsl(null); final ServerBuilder serverBuilder = Server.builder() .service("/foo", (ctx, req) -> HttpResponse.of(200)); serverBuilder.tlsSelfSigned(); ArmeriaConfigurationUtil.configureServer(serverBuilder, armeriaSettings); final Server server = serverBuilder.build(); assertThat(server.defaultHostname()).isEqualTo("host.name.com"); assertThat(server.config().maxNumConnections()).isEqualTo(5000); assertThat(server.config().isDateHeaderEnabled()).isFalse(); assertThat(server.config().isServerHeaderEnabled()).isTrue(); assertThat(server.config().defaultVirtualHost().maxRequestLength()).isEqualTo(10485761); assertThat(server.config().ports()).hasSize(3); assertThat(server.config().ports()).containsExactly( new ServerPort(8080, SessionProtocol.HTTP), new ServerPort(new InetSocketAddress("127.0.0.1", 8081), SessionProtocol.HTTPS), new ServerPort(8443, SessionProtocol.HTTPS, SessionProtocol.PROXY) ); assertThat(server.config().http1MaxChunkSize()).isEqualTo(4000); assertThat(server.config().http1MaxInitialLineLength()).isEqualTo(4096); assertThat(server.config().http1MaxInitialLineLength()).isEqualTo(4096); assertThat(server.config().http2InitialConnectionWindowSize()).isEqualTo(1024 * 1024 * 2); assertThat(server.config().http2InitialStreamWindowSize()).isEqualTo(1024 * 1024 * 2); assertThat(server.config().http2MaxFrameSize()).isEqualTo(16385); assertThat(server.config().http2MaxHeaderListSize()).isEqualTo(8193); assertThat(server.config().proxyProtocolMaxTlvSize()).isEqualTo(65320); }