Class CorsConfig.Builder
java.lang.Object
cloud.opencode.base.web.cors.CorsConfig.Builder
- Enclosing class:
CorsConfig
Builder for CorsConfig - fluent API for constructing CORS configurations.
CorsConfig 构建器 - 用于构建 CORS 配置的流式 API。
- Since:
- JDK 25, opencode-base-web V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
-
Method Summary
Modifier and TypeMethodDescriptionallowCredentials(boolean allowCredentials) Sets whether credentials (cookies, authorization) are allowed.allowHeader(String... headers) Adds allowed request headers.allowMethod(String... methods) Adds allowed HTTP methods.allowOrigin(String... origins) Adds allowed origins.build()Builds the CorsConfig.exposeHeader(String... headers) Adds exposed response headers.maxAge(long seconds) Sets the max age for preflight request caching (in seconds).
-
Method Details
-
allowOrigin
Adds allowed origins. 添加允许的来源。- Parameters:
origins- the origins to allow - 允许的来源- Returns:
- this builder - 此构建器
-
allowMethod
Adds allowed HTTP methods. 添加允许的 HTTP 方法。- Parameters:
methods- the methods to allow - 允许的方法- Returns:
- this builder - 此构建器
-
allowHeader
Adds allowed request headers. 添加允许的请求头部。- Parameters:
headers- the headers to allow - 允许的头部- Returns:
- this builder - 此构建器
-
exposeHeader
Adds exposed response headers. 添加暴露的响应头部。- Parameters:
headers- the headers to expose - 要暴露的头部- Returns:
- this builder - 此构建器
-
allowCredentials
Sets whether credentials (cookies, authorization) are allowed. 设置是否允许凭证(cookies、authorization)。- Parameters:
allowCredentials- true to allow credentials - true 表示允许凭证- Returns:
- this builder - 此构建器
-
maxAge
Sets the max age for preflight request caching (in seconds). 设置预检请求缓存的最大时间(秒)。- Parameters:
seconds- the max age in seconds (must be non-negative) - 最大时间(秒,必须为非负数)- Returns:
- this builder - 此构建器
- Throws:
IllegalArgumentException- if seconds is negative - 如果秒数为负数
-
build
Builds the CorsConfig. 构建 CorsConfig。- Returns:
- the CorsConfig - CorsConfig 实例
- Throws:
IllegalStateException- if allowCredentials is true and wildcard origin is used - 如果 allowCredentials 为 true 且使用了通配符来源
-