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
This commit is contained in:
parent
3d8d843198
commit
1464abe765
@ -17,7 +17,7 @@ package io.netty.example.http.cors;
|
|||||||
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
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.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
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
|
* A simple handler which will simple return a successful Http
|
||||||
* response for any request.
|
* response for any request.
|
||||||
*/
|
*/
|
||||||
public class OkResponseHandler extends ChannelInboundHandlerAdapter {
|
public class OkResponseHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
|
|
||||||
@Override
|
@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);
|
final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
response.headers().set("custom-response-header", "Some value");
|
response.headers().set("custom-response-header", "Some value");
|
||||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||||
|
Loading…
Reference in New Issue
Block a user