Search in sources :

Example 1 with CorsHandler

use of io.netty.handler.codec.http.cors.CorsHandler in project netty by netty.

the class HttpCorsServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpResponseEncoder());
    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new CorsHandler(corsConfig));
    pipeline.addLast(new OkResponseHandler());
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) CorsConfig(io.netty.handler.codec.http.cors.CorsConfig) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) CorsHandler(io.netty.handler.codec.http.cors.CorsHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)1 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)1 CorsConfig (io.netty.handler.codec.http.cors.CorsConfig)1 CorsHandler (io.netty.handler.codec.http.cors.CorsHandler)1 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)1