Correctly release inbound data in example. (#8105)
Motivation: We need to release the inbound data to ensure there are no leaks. Modifications: Extend SimpleChannelInboundHandler which will release inbound data by default. Result: No more leaks.
This commit is contained in:
parent
fef462c043
commit
cda4f88ca2
@ -18,16 +18,18 @@ package io.netty.example.http.helloworld;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
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.HttpObject;
|
||||||
import io.netty.handler.codec.http.HttpUtil;
|
import io.netty.handler.codec.http.HttpUtil;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
|
||||||
public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter {
|
public class HttpHelloWorldServerHandler extends SimpleChannelInboundHandler<HttpObject> {
|
||||||
private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' };
|
private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' };
|
||||||
|
|
||||||
private static final AsciiString CONTENT_TYPE = AsciiString.cached("Content-Type");
|
private static final AsciiString CONTENT_TYPE = AsciiString.cached("Content-Type");
|
||||||
@ -41,7 +43,7 @@ public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
|
||||||
if (msg instanceof HttpRequest) {
|
if (msg instanceof HttpRequest) {
|
||||||
HttpRequest req = (HttpRequest) msg;
|
HttpRequest req = (HttpRequest) msg;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user