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;
}
}
Aggregations