本文整理汇总了Java中io.vertx.ext.web.handler.CorsHandler.allowedHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java CorsHandler.allowedHeaders方法的具体用法?Java CorsHandler.allowedHeaders怎么用?Java CorsHandler.allowedHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.handler.CorsHandler
的用法示例。
在下文中一共展示了CorsHandler.allowedHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enableCors
import io.vertx.ext.web.handler.CorsHandler; //导入方法依赖的package包/类
/**
* @param router to add handler to
* @param allowedOriginPattern origin pattern
* @param allowCredentials allowed credentials
* @param maxAge in seconds
* @param allowedHeaders set of headers or null for none
* @param methods list of methods or empty for all
*/
public void enableCors(Router router,
String allowedOriginPattern,
boolean allowCredentials,
int maxAge,
Set<String> allowedHeaders,
HttpMethod... methods) {
CorsHandler handler = CorsHandler.create(allowedOriginPattern)
.allowCredentials(allowCredentials)
.maxAgeSeconds(maxAge);
if (methods == null || methods.length == 0) { // if not given than all
methods = HttpMethod.values();
}
for (HttpMethod method : methods) {
handler.allowedMethod(method);
}
handler.allowedHeaders(allowedHeaders);
router.route().handler(handler);
}
示例2: addCorsHandler
import io.vertx.ext.web.handler.CorsHandler; //导入方法依赖的package包/类
private static void addCorsHandler(Router router, CorsConfig corsConfig) {
if (corsConfig != null) {
CorsHandler corsHandler = CorsHandler.create(corsConfig.getAllowedOriginPattern());
if (corsConfig.getAllowedMethods() != null) {
corsHandler.allowedMethods(corsConfig.getAllowedMethods());
}
if (corsConfig.getAllowCredentials() != null) {
corsHandler.allowCredentials(corsConfig.getAllowCredentials());
}
if (corsConfig.getAllowedHeaders() != null) {
corsHandler.allowedHeaders(corsConfig.getAllowedHeaders());
}
if (corsConfig.getExposedHeaders() != null) {
corsHandler.exposedHeaders(corsConfig.getExposedHeaders());
}
if (corsConfig.getMaxAgeSeconds() != null) {
corsHandler.maxAgeSeconds(corsConfig.getMaxAgeSeconds());
}
router.route().handler(corsHandler);
}
}
示例3: route
import io.vertx.ext.web.handler.CorsHandler; //导入方法依赖的package包/类
private Route route(final CorsRoute corsRoute) {
final CorsHandler corsHandler = CorsHandler.create(corsRoute.getAllowedOriginPattern());
if (corsRoute.getAllowCredentials() != null)
corsHandler.allowCredentials(corsRoute.getAllowCredentials());
if (corsRoute.getAllowHeaders() != null)
corsHandler.allowedHeaders(corsRoute.getAllowHeaders());
if (corsRoute.getAllowMethods() != null)
corsHandler.allowedMethods(corsRoute.getAllowMethods());
if (corsRoute.getExposeHeaders() != null)
corsHandler.exposedHeaders(corsRoute.getExposeHeaders());
if (corsRoute.getFromPath() == null) {
if (corsRoute.getFromMethod() == null) {
return router.route().handler(corsHandler);
} else {
throw new IllegalArgumentException("Cannot configure CORS for a specific Method without a Path");
}
} else if (corsRoute.getFromMethod() == null) {
return router.route(corsRoute.getFromPath()).handler(corsHandler);
} else {
return router.route(corsRoute.getFromMethod(), corsRoute.getFromPath()).handler(corsHandler);
}
}