Example usage for io.netty.handler.codec.http.cors CorsConfigBuilder forAnyOrigin

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

Introduction

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

Prototype

public static CorsConfigBuilder forAnyOrigin() 

Source Link

Document

Creates a Builder instance with it's origin set to '*'.

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  w  w .java 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.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()));
    }/*from   w  w  w . j av a 2s . 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.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()));
    }//from   w w  w .  j a  v  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 DefaultResponseHandler());
}

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());
    }/*w w  w .j  a v  a2s  .  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));
}

From source file:org.infinispan.server.endpoint.subsystem.RestSubsystemAdd.java

License:Open Source License

private List<CorsConfig> getCorsConfig(ModelNode modelNode) {
    List<CorsConfig> corsConfigList = new ArrayList<>();
    if (modelNode.hasDefined(ModelKeys.CORS_RULE)) {
        List<ModelNode> rules = modelNode.get(ModelKeys.CORS_RULE).asList();
        for (ModelNode rule : rules) {
            ModelNode ruleDefinition = rule.get(rule.keys().iterator().next());
            Integer maxAgeSeconds = extractInt(ruleDefinition, ModelKeys.MAX_AGE_SECONDS);
            Boolean allowCredentials = extractBool(ruleDefinition, ModelKeys.ALLOW_CREDENTIALS);
            String[] origins = asArray(ruleDefinition, ModelKeys.ALLOWED_ORIGINS);
            String[] methods = asArray(ruleDefinition, ModelKeys.ALLOWED_METHODS);
            String[] headers = asArray(ruleDefinition, ModelKeys.ALLOWED_HEADERS);
            String[] exposes = asArray(ruleDefinition, ModelKeys.EXPOSE_HEADERS);

            HttpMethod[] httpMethods = Arrays.stream(methods).map(HttpMethod::valueOf)
                    .toArray(HttpMethod[]::new);

            CorsConfigBuilder builder;/*from w w  w.java  2s.  com*/
            if (Arrays.stream(origins).anyMatch(s -> s.equals("*"))) {
                builder = CorsConfigBuilder.forAnyOrigin();
            } else {
                builder = CorsConfigBuilder.forOrigins(origins);
            }
            builder.allowedRequestMethods(httpMethods);
            if (headers.length > 0)
                builder.allowedRequestHeaders(headers);
            if (exposes.length > 0)
                builder.exposeHeaders(exposes);
            if (maxAgeSeconds != null)
                builder.maxAge(maxAgeSeconds);
            if (allowCredentials)
                builder.allowCredentials();
            corsConfigList.add(builder.build());
        }
    }
    return corsConfigList;
}