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); }
/** * 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(); }
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. } }
private static Service<?, ?> service(ServerBuilder sb) { final Server server = sb.build(); return server.config().defaultVirtualHost().serviceConfigs().get(0).service(); }
server.config().defaultVirtualHost(), localAddress().getHostString(), path(),