Example usage for io.netty.handler.codec.http.cors CorsHandler CorsHandler

List of usage examples for io.netty.handler.codec.http.cors CorsHandler CorsHandler

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.cors CorsHandler CorsHandler.

Prototype

public CorsHandler(final CorsConfig config) 

Source Link

Document

Creates a new instance with a single CorsConfig .

Usage

From source file:com.cmz.http.cors.HttpCorsServerInitializer.java

License:Apache License

@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()));
    }/*from  w  ww.  j  ava  2s. c  o m*/
    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());
}

From source file:com.hop.hhxx.example.http.cors.HttpCorsServerInitializer.java

License:Apache License

@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()));
    }//  w w w  . j ava 2 s. c  om
    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 io.netty.example.http.cors.OkResponseHandler());
}

From source file:com.phei.netty.nio.http.cors.HttpCorsServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {
    CorsConfig corsConfig = CorsConfig.withAnyOrigin().build();
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }/*from w w  w  .j av a 2  s  .c  o  m*/
    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());
}

From source file:com.shun.liu.shunzhitianxia.recevier.http.HttpRecevierServerInitializer.java

License:Apache License

@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()));
    }//  w w w .ja v a2  s .com
    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 DefaultResponseHandler());
}

From source file:com.topsec.bdc.platform.api.test.http.cors.HttpCorsServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) {

    CorsConfig corsConfig = CorsConfig.withAnyOrigin().build();
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }/*from  ww w .  ja va  2 s . c o  m*/
    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());
}

From source file:edumsg.netty.EduMsgNettyServerInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel arg0) {
    CorsConfig corsConfig = CorsConfig.withAnyOrigin()
            .allowedRequestHeaders("X-Requested-With", "Content-Type", "Content-Length")
            .allowedRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE,
                    HttpMethod.OPTIONS)/*  w  w w  . java 2  s .c  om*/
            .build();
    ChannelPipeline p = arg0.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(arg0.alloc()));
    }
    p.addLast("decoder", new HttpRequestDecoder());
    p.addLast("encoder", new HttpResponseEncoder());
    p.addLast(new CorsHandler(corsConfig));
    p.addLast(new EduMsgNettyServerHandler());
}

From source file:godfinger.http.HttpServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel channel) {
    CorsConfig corsConfig = CorsConfig.withAnyOrigin().allowCredentials()
            .allowedRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE)
            .allowedRequestHeaders("accept", "content-type", "session-id").build();

    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new FaviconHandler());
    pipeline.addLast(new CorsHandler(corsConfig));
    pipeline.addLast(new HttpObjectAggregator(1024 * 1024));
    pipeline.addLast(new HttpRequestHandler(requestProcessor));
}

From source file:io.blobkeeper.server.initializer.BlobKeeperServerInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    CorsConfig corsConfig = CorsConfig.withAnyOrigin().allowedRequestMethods(DELETE, GET, OPTIONS, POST, PUT)
            .allowedRequestHeaders(serverConfiguration.getAllowedHeaders()).build();

    ChannelPipeline pipeline = socketChannel.pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("cors", new CorsHandler(corsConfig));

    pipeline.addLast("writer", fileWriterHandlerProvider.get());
    pipeline.addLast("reader", fileReaderHandler);
    pipeline.addLast("deleter", fileDeleteHandler);
}

From source file:nayan.netty.server.HttpStaticFileServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.

    CorsConfig corsConfig = CorsConfig.withAnyOrigin().build();

    ChannelPipeline pipeline = ch.pipeline();

    // Uncomment the following line if you want HTTPS
    //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
    //engine.setUseClientMode(false);
    //pipeline.addLast("ssl", new SslHandler(engine));

    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(8388608)); // 8MB
    //pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("cors", new CorsHandler(corsConfig));

    pipeline.addLast("handler", new HttpStaticFileServerHandler());
}

From source file:org.dcache.http.HttpTransferService.java

License:Open Source License

protected void addChannelHandlers(ChannelPipeline pipeline) {
    // construct HttpRequestDecoder as netty defaults, except configurable chunk size
    pipeline.addLast("decoder", new HttpRequestDecoder(4096, 8192, getChunkSize(), true));
    pipeline.addLast("encoder", new HttpResponseEncoder());

    if (LOGGER.isDebugEnabled()) {
        pipeline.addLast("logger", new LoggingHandler());
    }//from w w w.  j  av  a 2s  .co m
    pipeline.addLast("idle-state-handler",
            new IdleStateHandler(0, 0, clientIdleTimeout, clientIdleTimeoutUnit));
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("keepalive", new KeepAliveHandler());

    if (!customHeaders.isEmpty()) {
        pipeline.addLast("custom-headers", new CustomResponseHeadersHandler(customHeaders));
    }

    CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin()
            .allowedRequestMethods(GET, PUT, HEAD).allowedRequestHeaders(CONTENT_TYPE, AUTHORIZATION,
                    CONTENT_MD5, "Want-Digest", "suppress-www-authenticate")
            .build();
    pipeline.addLast("cors", new CorsHandler(corsConfig));

    pipeline.addLast("transfer", new HttpPoolRequestHandler(this, chunkSize));
}