OkResponseHandler should return a FullHttpResponse.
Motivation: Currently OkResponseHandler returns a DefaultHttpResponse which is not correct and it should be returning complete http response. Modifications: Updated OkResponseHandler to return an instance of DefaultFullHttpResponse. Result: It is not possible to add compression to the example without getting any errors.
This commit is contained in:
parent
f3b1816db8
commit
95b6ee80ca
@ -18,7 +18,8 @@ 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.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.http.DefaultHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class OkResponseHandler extends SimpleChannelInboundHandler<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
final DefaultHttpResponse response = new DefaultHttpResponse(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