Source:
public static void main(String[] args) throws Exception { AsyncContext.disable(); IoExecutor ioExecutor = NettyIoExecutors.createIoExecutor( Runtime.getRuntime().availableProcessors(), new IoThreadFactory("io-pool") ); DefaultHttpHeadersFactory headersFactory = new DefaultHttpHeadersFactory(false,false); try{ HttpSerializationProvider serializer = HttpSerializationProviders.jsonSerializer(new JacksonSerializationProvider()); HttpServers .forPort(8080) .executionStrategy(HttpExecutionStrategies.noOffloadsStrategy()) .ioExecutor(ioExecutor) .disableDrainingRequestPayloadBody() .protocols(HttpProtocolConfigs.h1().headersFactory(headersFactory).build()) .appendConnectionAcceptorFilter(delegate -> new ConnectionAcceptor() { @Override public Completable accept(ConnectionContext context) { ((NettyConnectionContext)context).updateFlushStrategy((current, isOrig) -> FlushStrategies.flushOnEnd()); return delegate.accept(context); } }) .listenAndAwait((ctx, request, responseFactory) -> { ((NettyConnectionContext)ctx).updateFlushStrategy(((current, isCurrentOriginal) -> FlushStrategies.flushOnEach())); if(request.path().equals("/json")) { Map<String, String> obj = new HashMap<String, String>(); obj.put("message", "Hello, World!"); return succeeded(responseFactory.ok() .payloadBody(obj, serializer.serializerFor(Map.class)) .addHeader("Date", GetCurrentTime()) .addHeader("Server", "TFB")); } if(request.path().equals("/plaintext")) { return succeeded(responseFactory.ok() .payloadBody("Hello, World!", HttpSerializationProviders.textSerializer()) .addHeader("Date", GetCurrentTime()) .addHeader("Server", "TFB")); }; return null; }) .awaitShutdown(); } catch (Exception e) { } }

Target:
public static void main(String[] args) throws Exception { AsyncContext.disable(); IoExecutor ioExecutor = NettyIoExecutors.createIoExecutor( Runtime.getRuntime().availableProcessors(), new IoThreadFactory("io-pool") ); DefaultHttpHeadersFactory headersFactory = new DefaultHttpHeadersFactory(false,false); HttpSerializationProvider serializer = HttpSerializationProviders.jsonSerializer(new JacksonSerializationProvider()); HttpServers .forPort(8080) .executionStrategy(HttpExecutionStrategies.noOffloadsStrategy()) .ioExecutor(ioExecutor) .disableDrainingRequestPayloadBody() .protocols(HttpProtocolConfigs.h1().headersFactory(headersFactory).build()) .appendConnectionAcceptorFilter(delegate -> new ConnectionAcceptor() { @Override public Completable accept(ConnectionContext context) { ((NettyConnectionContext)context).updateFlushStrategy((current, isOrig) -> FlushStrategies.flushOnEnd()); return delegate.accept(context); } }) .listenAndAwait((ctx, request, responseFactory) -> { ((NettyConnectionContext)ctx).updateFlushStrategy(((current, isCurrentOriginal) -> FlushStrategies.flushOnEach())); if(request.path().equals("/json")) { Map<String, String> obj = new HashMap<String, String>(); obj.put("message", "Hello, World!"); return succeeded(responseFactory.ok() .payloadBody(obj, serializer.serializerFor(Map.class)) .addHeader("Date", getCurrentTime()) .addHeader("Server", "ServiceTalk")); } if(request.path().equals("/plaintext")) { return succeeded(responseFactory.ok() .payloadBody("Hello, World!", HttpSerializationProviders.textSerializer()) .addHeader("Date", getCurrentTime()) .addHeader("Server", "ServiceTalk")); }; return null; }) .awaitShutdown(); }