private static String makeAResponse(Origin origin) { return format("Response From %s - %s", origin.hostAndPortString(), randomUUID().toString()); }
@Override public String toString() { return toStringHelper(this) .add("host", this.origin.hostAndPortString()) .add("channel", toString(channel)) .toString(); }
private static String hosts(Iterable<RemoteHost> origins) { return stream(origins.spliterator(), false) .map(host -> host.origin().hostAndPortString()) .collect(joining(", ")); } }
private io.netty.handler.codec.http.HttpRequest makeRequest(LiveHttpRequest request) { DefaultHttpRequest nettyRequest = toNettyRequest(request); Optional<String> host = request.header(HOST); if (!host.isPresent()) { nettyRequest.headers().set(HOST, nettyConnection.getOrigin().hostAndPortString()); } return nettyRequest; } }
private HttpRequest newHealthCheckRequestFor(Origin origin) { return HttpRequest.get(healthCheckUri) .header(HOST, origin.hostAndPortString()) .build(); }
@Override protected LiveHttpResponse doHandle(LiveHttpRequest request) { HttpRequest fullRequest = Mono.from(request.aggregate(0x100000)).block(); String responseBody = format("Response From %s - %s, received content digest: %s", origin.hostAndPortString(), randomUUID(), fullRequest.bodyAs(UTF_8).hashCode()); return HttpResponse.response(OK) .header(CONTENT_TYPE, HTML_UTF_8.toString()) .header(CONTENT_LENGTH, responseBody.getBytes(UTF_8).length) .body(responseBody, UTF_8) .build() .stream(); } }
private static HttpServer createHttpServer(Origin origin) { LOG.info("creating server for {}", origin.hostAndPortString()); return new NettyServerBuilder() .name(origin.hostAndPortString()) .setServerEventLoopFactory(serverEventLoopFactory) .setHttpConnector(new WebServerConnectorFactory().create(new HttpConnectorConfig(origin.port()))) .httpHandler(new StandardHttpRouter().add("/*", new AppHandler(origin))) .build(); }
private static Info information(LiveHttpRequest request, Origin origin, boolean longFormatEnabled) { Info info = new Info() .add("method", request.method()) .add("uri", request.url()) .add("origin", origin != null ? origin.hostAndPortString() : "N/A"); if (longFormatEnabled) { info.add("headers", request.headers()); } return info; }