@Override public String toString() { String strVal = this.strVal; if (strVal == null) { this.strVal = strVal = toString( getClass(), ports(), null, virtualHosts(), workerGroup(), shutdownWorkerGroupOnStop(), maxNumConnections(), idleTimeoutMillis(), defaultRequestTimeoutMillis(), defaultMaxRequestLength(), verboseResponses(), http2InitialConnectionWindowSize(), http2InitialStreamWindowSize(), http2MaxStreamsPerConnection(), http2MaxFrameSize(), http2MaxHeaderListSize(), http1MaxInitialLineLength(), http1MaxHeaderSize(), http1MaxChunkSize(), proxyProtocolMaxTlvSize(), gracefulShutdownQuietPeriod(), gracefulShutdownTimeout(), blockingTaskExecutor(), meterRegistry(), serviceLoggerPrefix(), accessLogWriter(), shutdownAccessLogWriterOnStop(), channelOptions(), childChannelOptions(), clientAddressSources(), clientAddressTrustedProxyFilter(), clientAddressFilter() ); } return strVal; }
private String hostname(ChannelHandlerContext ctx, HttpHeaders headers) { final String hostname = headers.authority(); if (hostname == null) { // Fill the authority with the default host name and current port, just in case the client did not // send it. final String defaultHostname = config.defaultVirtualHost().defaultHostname(); final int port = ((InetSocketAddress) ctx.channel().localAddress()).getPort(); headers.authority(defaultHostname + ':' + port); return defaultHostname; } final int hostnameColonIdx = hostname.lastIndexOf(':'); if (hostnameColonIdx < 0) { return hostname; } return hostname.substring(0, hostnameColonIdx); }
private void finishDoStop(CompletableFuture<Void> future) { // TODO(trustin): Add shutdownBlockingTaskExecutorOnStop // TODO(trustin): Count the pending blocking tasks and wait until it goes zero. if (!config.shutdownAccessLogWriterOnStop()) { future.complete(null); return; } config.accessLogWriter().shutdown().exceptionally(cause -> { logger.warn("Failed to close the {}:", AccessLogWriter.class.getSimpleName(), cause); return null; }).thenRunAsync(() -> future.complete(null), config.startStopExecutor()); }
@Override protected CompletionStage<Void> doStart() { if (config().gracefulShutdownQuietPeriod().isZero()) { gracefulShutdownSupport = GracefulShutdownSupport.createDisabled(); } else { gracefulShutdownSupport = GracefulShutdownSupport.create(config().gracefulShutdownQuietPeriod(), config().blockingTaskExecutor()); final List<ServerPort> ports = config().ports();
if (cause != null) { final HttpResponse errorRes; if (ctx.server().config().verboseResponses()) { errorRes = HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR, MediaType.PLAIN_TEXT_UTF_8,
@Override public void serviceAdded(ServiceConfig cfg) { if (maxInboundMessageSizeBytes == NO_MAX_INBOUND_MESSAGE_SIZE) { maxInboundMessageSizeBytes = (int) Math.min(cfg.server().config().defaultMaxRequestLength(), Integer.MAX_VALUE); } }
requestTimeoutMillis = serverCfg.defaultRequestTimeoutMillis(); maxRequestLength = serverCfg.defaultMaxRequestLength();
void start() throws Exception { boolean success = false; try { assert armeriaServer != null; server = serverFactory.apply(armeriaServer.config().blockingTaskExecutor()); connector = new ArmeriaConnector(server); server.addConnector(connector); if (!server.isStarted()) { logger.info("Starting an embedded Jetty: {}", server); server.start(); startedServer = true; } else { startedServer = false; } success = true; } finally { if (!success) { server = null; connector = null; } } }
HttpServerHandler(ServerConfig config, GracefulShutdownSupport gracefulShutdownSupport, @Nullable HttpObjectEncoder responseEncoder, SessionProtocol protocol, @Nullable ProxiedAddresses proxiedAddresses) { assert protocol == H1 || protocol == H1C || protocol == H2; this.config = requireNonNull(config, "config"); this.gracefulShutdownSupport = requireNonNull(gracefulShutdownSupport, "gracefulShutdownSupport"); this.protocol = requireNonNull(protocol, "protocol"); this.responseEncoder = responseEncoder; this.proxiedAddresses = proxiedAddresses; unfinishedRequests = new IdentityHashMap<>(); accessLogWriter = config.accessLogWriter(); }
final Server server = new Server(new ServerConfig( ports, normalizeDefaultVirtualHost(defaultVirtualHost, defaultSslContext), virtualHosts, workerGroup, shutdownWorkerGroupOnStop, startStopExecutor, maxNumConnections,
static HttpHeaders statusToTrailers(ServiceRequestContext ctx, Status status, boolean headersSent) { final HttpHeaders trailers; if (headersSent) { // Normal trailers. trailers = new DefaultHttpHeaders(); } else { // Trailers only response trailers = new DefaultHttpHeaders(true, 3, true) .status(HttpStatus.OK) .set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto"); } trailers.add(GrpcHeaderNames.GRPC_STATUS, Integer.toString(status.getCode().value())); if (status.getDescription() != null) { trailers.add(GrpcHeaderNames.GRPC_MESSAGE, StatusMessageEscaper.escape(status.getDescription())); } if (ctx.server().config().verboseResponses() && status.getCause() != null) { final ThrowableProto proto = GrpcStatus.serializeThrowable(status.getCause()); trailers.add(GrpcHeaderNames.ARMERIA_GRPC_THROWABLEPROTO_BIN, Base64.getEncoder().encodeToString(proto.toByteArray())); } return trailers; }
inboundTrafficController, cfg.defaultMaxRequestLength());
@Override public ExecutorService blockingTaskExecutor() { if (blockingTaskExecutor != null) { return blockingTaskExecutor; } return blockingTaskExecutor = makeContextAware(server().config().blockingTaskExecutor()); }
appException = (TApplicationException) cause; } else { if (ctx.server().config().verboseResponses()) { appException = new TApplicationException( TApplicationException.INTERNAL_ERROR,
HttpUtil.isKeepAlive(nettyReq), inboundTrafficController, cfg.defaultMaxRequestLength());
/** * Returns the hostname of the default {@link VirtualHost}, which is the hostname of the machine unless * configured explicitly via {@link ServerBuilder#defaultVirtualHost(VirtualHost)}. */ public String defaultHostname() { return config().defaultVirtualHost().defaultHostname(); }
if (ctx.server().config().verboseResponses()) { errorRes = HttpResponse.of(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8, "Failed to decode a %s header: %s", serializationFormat,
@Override public void serviceAdded(ServiceConfig cfg) throws Exception { if (maxInboundMessageSizeBytes == NO_MAX_INBOUND_MESSAGE_SIZE) { maxInboundMessageSizeBytes = (int) cfg.server().config().defaultMaxRequestLength(); } }
private static ServiceConfig findServiceConfig(Server server, String path, Service<?, ?> service) { for (ServiceConfig cfg : server.config().defaultVirtualHost().serviceConfigs()) { final Optional<String> exactPath = cfg.pathMapping().exactPath(); if (!exactPath.isPresent()) { continue; } if (!path.equals(exactPath.get())) { continue; } if (cfg.service().as(service.getClass()).isPresent()) { return cfg; } } throw new Error(); // Never reaches here. } }
if (cause != null) { final HttpResponse errorRes; if (ctx.server().config().verboseResponses()) { errorRes = HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR, MediaType.PLAIN_TEXT_UTF_8,