@Override public Map<String, HttpHandler> adminInterfaceHandlers() { return ImmutableMap.of("status", request -> just( response(OK) .addHeader(CONTENT_TYPE, APPLICATION_JSON) .body(format("{ name: \"%s\" status: \"%s\" }", name, status), UTF_8) .build() .toStreamingResponse())); }
public Observable<FullHttpResponse> toFullHttpResponse(int maxContentBytes) { CompositeByteBuf byteBufs = compositeBuffer(); return body .lift(disableFlowControl()) .doOnError(e -> byteBufs.release()) .collect(() -> byteBufs, (composite, part) -> { long newSize = composite.readableBytes() + part.readableBytes(); if (newSize > maxContentBytes) { release(composite); release(part); throw new ContentOverflowException(format("Maximum content size exceeded. Maximum size allowed is %d bytes.", maxContentBytes)); } composite.addComponent(part); composite.writerIndex(composite.writerIndex() + part.readableBytes()); }) .map(StreamingHttpResponse::decodeAndRelease) .map(decoded -> new FullHttpResponse.Builder(this, decoded).build()); }