public static void main(String[] args) {
String ip = "127.0.0.1";
int port = 8080;
ChannelInitializer<SocketChannel> channelInit = new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
CorsConfig corsConfig = CorsConfig.withAnyOrigin()
.allowedRequestHeaders("content-type","accept","MyCustomHeader")
.allowedRequestMethods(PUT,POST,GET,DELETE)
.build();
p.addLast(new HttpResponseEncoder());
p.addLast(new HttpRequestDecoder());
p.addLast(new HttpObjectAggregator(65536));
p.addLast(new ChunkedWriteHandler());
p.addLast(new CorsHandler(corsConfig));
p.addLast(new SimpleCORSHandler());
}
};
NettyServerUtil.newHttpServerBootstrap(ip, port, channelInit);
}
NettyHttpServerWithCORS.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:netty-cookbook
作者:
评论列表
文章目录