From 5a987925e75c0b08b28e957555fb9c21bc36842c Mon Sep 17 00:00:00 2001 From: Andrei Ivanov Date: Wed, 3 Feb 2021 20:10:59 +0300 Subject: [PATCH] fixed connection handling --- .../disthene/reader/server/ReaderServerHandler.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/iponweb/disthene/reader/server/ReaderServerHandler.java b/src/main/java/net/iponweb/disthene/reader/server/ReaderServerHandler.java index 7f1f7420..066ca967 100644 --- a/src/main/java/net/iponweb/disthene/reader/server/ReaderServerHandler.java +++ b/src/main/java/net/iponweb/disthene/reader/server/ReaderServerHandler.java @@ -62,13 +62,13 @@ public void channelRead(ChannelHandlerContext ctx, Object message) { } else { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND); } - ctx.write(response).addListener(ChannelFutureListener.CLOSE); if (keepAlive) { response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); - ctx.write(response); + ctx.writeAndFlush(response, ctx.voidPromise()); } else { - ctx.write(response).addListener(ChannelFutureListener.CLOSE); + response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE); + ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } } catch (EvaluationException | ParameterParsingException | LogarithmicScaleNotAllowed e) { FullHttpResponse response; @@ -77,12 +77,12 @@ public void channelRead(ChannelHandlerContext ctx, Object message) { } else { response = new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST, Unpooled.wrappedBuffer(("Ohoho.. We have a problem: " + e.getMessage()).getBytes())); } - ctx.write(response).addListener(ChannelFutureListener.CLOSE); + ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } catch (Exception e) { logger.error("Invalid request: " + e.getMessage()); logger.debug("Invalid request: ", e); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(("Ohoho.. We have a problem: " + e.getMessage()).getBytes())); - ctx.write(response).addListener(ChannelFutureListener.CLOSE); + ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } finally { ((HttpContent) message).content().release(); }