Search in sources :

Example 1 with CorsConfigBuilder

use of io.netty.handler.codec.http.cors.CorsConfigBuilder in project java by wavefrontHQ.

the class PushAgent method getCorsConfig.

@Nullable
protected CorsConfig getCorsConfig(String port) {
    List<String> ports = proxyConfig.getCorsEnabledPorts();
    List<String> corsOrigin = proxyConfig.getCorsOrigin();
    if (ports.equals(ImmutableList.of("*")) || ports.contains(port)) {
        CorsConfigBuilder builder;
        if (corsOrigin.equals(ImmutableList.of("*"))) {
            builder = CorsConfigBuilder.forOrigin(corsOrigin.get(0));
        } else {
            builder = CorsConfigBuilder.forOrigins(corsOrigin.toArray(new String[0]));
        }
        builder.allowedRequestHeaders("Content-Type", "Referer", "User-Agent");
        builder.allowedRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT);
        if (proxyConfig.isCorsAllowNullOrigin()) {
            builder.allowNullOrigin();
        }
        return builder.build();
    } else {
        return null;
    }
}
Also used : CorsConfigBuilder(io.netty.handler.codec.http.cors.CorsConfigBuilder) Nullable(javax.annotation.Nullable)

Aggregations

CorsConfigBuilder (io.netty.handler.codec.http.cors.CorsConfigBuilder)1 Nullable (javax.annotation.Nullable)1