From 1464abe765a9dcea9a4989c26fc4ab7fc4f81698 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 3 Jul 2014 18:13:03 +0900 Subject: [PATCH] Let OkResponseHandler extend SimpleChannelInboundHandler Motivation: OkResponseHandler is the last handler in the pipeline of the HTTP CORS example. It is responsible for releasing all messages it handled. Modification: Extend SimpleChannelInboundHandler instead of ChannelInboundHandlerAdapter Result: Fixed a leak --- .../java/io/netty/example/http/cors/OkResponseHandler.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/example/src/main/java/io/netty/example/http/cors/OkResponseHandler.java b/example/src/main/java/io/netty/example/http/cors/OkResponseHandler.java index 1a334d8ff8..4ad71e6296 100644 --- a/example/src/main/java/io/netty/example/http/cors/OkResponseHandler.java +++ b/example/src/main/java/io/netty/example/http/cors/OkResponseHandler.java @@ -17,7 +17,7 @@ package io.netty.example.http.cors; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -27,10 +27,9 @@ import io.netty.handler.codec.http.HttpVersion; * A simple handler which will simple return a successful Http * response for any request. */ -public class OkResponseHandler extends ChannelInboundHandlerAdapter { - +public class OkResponseHandler extends SimpleChannelInboundHandler { @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) { + public void channelRead0(ChannelHandlerContext ctx, Object msg) { final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); response.headers().set("custom-response-header", "Some value"); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);