No need to use an unreleasable buffer - just wrap an array
This commit is contained in:
parent
357677d8fa
commit
cd275ba67e
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.example.http.helloworld;
|
package io.netty.example.http.helloworld;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
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;
|
||||||
@ -23,7 +22,6 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
|
|||||||
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.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.util.CharsetUtil;
|
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||||
import static io.netty.handler.codec.http.HttpHeaders.*;
|
import static io.netty.handler.codec.http.HttpHeaders.*;
|
||||||
@ -31,8 +29,7 @@ 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 ChannelInboundHandlerAdapter {
|
||||||
private static final ByteBuf CONTENT =
|
private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' };
|
||||||
Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Hello World", CharsetUtil.US_ASCII));
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||||
@ -48,7 +45,7 @@ public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
|
||||||
}
|
}
|
||||||
boolean keepAlive = isKeepAlive(req);
|
boolean keepAlive = isKeepAlive(req);
|
||||||
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, CONTENT.duplicate());
|
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
|
||||||
response.headers().set(CONTENT_TYPE, "text/plain");
|
response.headers().set(CONTENT_TYPE, "text/plain");
|
||||||
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
|
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user