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