1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package io.netty.example.http.cors;
17  
18  import io.netty.buffer.Unpooled;
19  import io.netty.channel.ChannelFutureListener;
20  import io.netty.channel.ChannelHandlerContext;
21  import io.netty.channel.SimpleChannelInboundHandler;
22  import io.netty.handler.codec.http.DefaultFullHttpResponse;
23  import io.netty.handler.codec.http.FullHttpResponse;
24  import io.netty.handler.codec.http.HttpResponseStatus;
25  import io.netty.handler.codec.http.HttpVersion;
26  
27  
28  
29  
30  
31  public class OkResponseHandler extends SimpleChannelInboundHandler<Object> {
32      @Override
33      public void channelRead0(ChannelHandlerContext ctx, Object msg) {
34          final FullHttpResponse response = new DefaultFullHttpResponse(
35                  HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER);
36          response.headers().set("custom-response-header", "Some value");
37          ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
38      }
39  }