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.channel.ChannelFutureListener;
19 import io.netty.channel.ChannelHandlerContext;
20 import io.netty.channel.SimpleChannelInboundHandler;
21 import io.netty.handler.codec.http.DefaultFullHttpResponse;
22 import io.netty.handler.codec.http.FullHttpResponse;
23 import io.netty.handler.codec.http.HttpResponseStatus;
24 import io.netty.handler.codec.http.HttpVersion;
25
26
27
28
29
30 public class OkResponseHandler extends SimpleChannelInboundHandler<Object> {
31 @Override
32 public void channelRead0(ChannelHandlerContext ctx, Object msg) {
33 final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
34 response.headers().set("custom-response-header", "Some value");
35 ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
36 }
37 }