Skip to content

Commit

Permalink
expose build
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Feb 25, 2025
1 parent 98e3054 commit 150f130
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public SELF disablePreflightResponseHeaders() {
/**
* Returns a newly-created {@link CorsPolicy} based on the properties of this builder.
*/
CorsPolicy build() {
public final CorsPolicy build() {
return new CorsPolicy(origins, originPredicate, routes, credentialsAllowed, maxAge,
nullOriginAllowed, exposedHeaders, allowAllRequestHeaders, allowedRequestHeaders,
allowedRequestMethods, preflightResponseHeadersDisabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2025 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.linecorp.armeria.server.cors.test;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import com.linecorp.armeria.common.HttpMethod;
import com.linecorp.armeria.server.cors.CorsPolicy;
import com.linecorp.armeria.server.cors.CorsPolicyBuilder;

class CorsBuilderTest {

@Test
void buildCorsPolicy() {
final String url = "http://example.com";
final CorsPolicyBuilder cb = CorsPolicy.builder(url);
cb.allowRequestMethods(HttpMethod.POST, HttpMethod.GET)
.allowRequestHeaders("allow_request_header")
.exposeHeaders("expose_header_1", "expose_header_2")
.preflightResponseHeader("x-preflight-cors", "Hello CORS");
final CorsPolicy policy = cb.build();
assertThat(policy.originPredicate().test(url)).isTrue();
}
}

0 comments on commit 150f130

Please sign in to comment.