Class CorsConfig.Builder

java.lang.Object
cloud.opencode.base.web.cors.CorsConfig.Builder
Enclosing class:
CorsConfig

public static final class CorsConfig.Builder extends Object
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 Details

    • allowOrigin

      public CorsConfig.Builder allowOrigin(String... origins)
      Adds allowed origins. 添加允许的来源。
      Parameters:
      origins - the origins to allow - 允许的来源
      Returns:
      this builder - 此构建器
    • allowMethod

      public CorsConfig.Builder allowMethod(String... methods)
      Adds allowed HTTP methods. 添加允许的 HTTP 方法。
      Parameters:
      methods - the methods to allow - 允许的方法
      Returns:
      this builder - 此构建器
    • allowHeader

      public CorsConfig.Builder allowHeader(String... headers)
      Adds allowed request headers. 添加允许的请求头部。
      Parameters:
      headers - the headers to allow - 允许的头部
      Returns:
      this builder - 此构建器
    • exposeHeader

      public CorsConfig.Builder exposeHeader(String... headers)
      Adds exposed response headers. 添加暴露的响应头部。
      Parameters:
      headers - the headers to expose - 要暴露的头部
      Returns:
      this builder - 此构建器
    • allowCredentials

      public CorsConfig.Builder allowCredentials(boolean allowCredentials)
      Sets whether credentials (cookies, authorization) are allowed. 设置是否允许凭证(cookies、authorization)。
      Parameters:
      allowCredentials - true to allow credentials - true 表示允许凭证
      Returns:
      this builder - 此构建器
    • maxAge

      public CorsConfig.Builder maxAge(long seconds)
      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

      public CorsConfig build()
      Builds the CorsConfig. 构建 CorsConfig。
      Returns:
      the CorsConfig - CorsConfig 实例
      Throws:
      IllegalStateException - if allowCredentials is true and wildcard origin is used - 如果 allowCredentials 为 true 且使用了通配符来源