Java Code Examples for com.linecorp.armeria.server.ServerBuilder#disableServerHeader()

The following examples show how to use com.linecorp.armeria.server.ServerBuilder#disableServerHeader() . 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: JsonTextSequencesTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.service("/seq/publisher",
               (ctx, req) -> JsonTextSequences.fromPublisher(Flux.just("foo", "bar", "baz", "qux")))
      .service("/seq/stream",
               (ctx, req) -> JsonTextSequences.fromStream(
                       Stream.of("foo", "bar", "baz", "qux"), MoreExecutors.directExecutor()))
      .service("/seq/custom-mapper",
               (ctx, req) -> JsonTextSequences.fromPublisher(
                       Flux.just("foo", "bar", "baz", "qux"),
                       new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)))
      .service("/seq/single",
               (ctx, req) -> JsonTextSequences.fromObject("foo"));
    sb.disableServerHeader();
    sb.disableDateHeader();
}
 
Example 2
Source File: ArmeriaConfigurationUtil.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Configures the {@link ServerBuilder} with the specified {@code settings}.
 */
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());
    }
}
 
Example 3
Source File: HealthCheckServiceTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.service("/hc", HealthCheckService.of(checker));
    sb.service("/hc_long_polling_disabled", HealthCheckService.builder()
                                                              .longPolling(0)
                                                              .build());
    sb.service("/hc_updatable", HealthCheckService.builder()
                                                  .updatable(true)
                                                  .build());
    sb.service("/hc_custom",
               HealthCheckService.builder()
                                 .healthyResponse(AggregatedHttpResponse.of(
                                         HttpStatus.OK,
                                         MediaType.PLAIN_TEXT_UTF_8,
                                         "ok"))
                                 .unhealthyResponse(AggregatedHttpResponse.of(
                                         HttpStatus.SERVICE_UNAVAILABLE,
                                         MediaType.PLAIN_TEXT_UTF_8,
                                         "not ok"))
                                 .updatable((ctx, req) -> {
                                     if (req.method() != HttpMethod.PUT) {
                                         throw HttpStatusException.of(HttpStatus.METHOD_NOT_ALLOWED);
                                     }
                                     return req.aggregate().thenApply(aReq -> {
                                         final String content = aReq.contentAscii();
                                         switch (content) {
                                             case "OK":
                                                 return HealthCheckUpdateResult.HEALTHY;
                                             case "KO":
                                                 return HealthCheckUpdateResult.UNHEALTHY;
                                             case "NOOP":
                                                 return HealthCheckUpdateResult.AS_IS;
                                             default:
                                                 throw HttpStatusException.of(HttpStatus.BAD_REQUEST);
                                         }
                                     });
                                 })
                                 .build());
    sb.gracefulShutdownTimeout(Duration.ofSeconds(10), Duration.ofSeconds(10));
    sb.disableServerHeader();
    sb.disableDateHeader();
}