File tree Expand file tree Collapse file tree 5 files changed +47
-8
lines changed
main/java/org/springframework/web/reactive/config
test/java/org/springframework/web/reactive/config
main/java/org/springframework/web/servlet/config/annotation
test/java/org/springframework/web/servlet/config/annotation
spring-web/src/main/java/org/springframework/web/cors Expand file tree Collapse file tree 5 files changed +47
-8
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -475,7 +475,6 @@ public void validateAllowCredentials() {
475
475
* @return the combined {@code CorsConfiguration}, or {@code this}
476
476
* configuration if the supplied configuration is {@code null}
477
477
*/
478
- @ Nullable
479
478
public CorsConfiguration combine (@ Nullable CorsConfiguration other ) {
480
479
if (other == null ) {
481
480
return this ;
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public class CorsRegistration {
35
35
36
36
private final String pathPattern ;
37
37
38
- private final CorsConfiguration config ;
38
+ private CorsConfiguration config ;
39
39
40
40
41
41
public CorsRegistration (String pathPattern ) {
@@ -149,7 +149,7 @@ public CorsRegistration maxAge(long maxAge) {
149
149
* @since 5.3
150
150
*/
151
151
public CorsRegistration combine (CorsConfiguration other ) {
152
- this .config .combine (other );
152
+ this .config = this . config .combine (other );
153
153
return this ;
154
154
}
155
155
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -73,4 +73,24 @@ public void allowCredentials() {
73
73
.containsExactly ("*" );
74
74
}
75
75
76
+ @ Test
77
+ void combine () {
78
+ CorsConfiguration otherConfig = new CorsConfiguration ();
79
+ otherConfig .addAllowedOrigin ("http://localhost:3000" );
80
+ otherConfig .addAllowedMethod ("*" );
81
+ otherConfig .applyPermitDefaultValues ();
82
+
83
+ this .registry .addMapping ("/api/**" ).combine (otherConfig );
84
+
85
+ Map <String , CorsConfiguration > configs = this .registry .getCorsConfigurations ();
86
+ assertThat (configs .size ()).isEqualTo (1 );
87
+ CorsConfiguration config = configs .get ("/api/**" );
88
+ assertThat (config .getAllowedOrigins ()).isEqualTo (Collections .singletonList ("http://localhost:3000" ));
89
+ assertThat (config .getAllowedMethods ()).isEqualTo (Collections .singletonList ("*" ));
90
+ assertThat (config .getAllowedHeaders ()).isEqualTo (Collections .singletonList ("*" ));
91
+ assertThat (config .getExposedHeaders ()).isEmpty ();
92
+ assertThat (config .getAllowCredentials ()).isNull ();
93
+ assertThat (config .getMaxAge ()).isEqualTo (Long .valueOf (1800 ));
94
+ }
95
+
76
96
}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public class CorsRegistration {
36
36
37
37
private final String pathPattern ;
38
38
39
- private final CorsConfiguration config ;
39
+ private CorsConfiguration config ;
40
40
41
41
42
42
public CorsRegistration (String pathPattern ) {
@@ -150,7 +150,7 @@ public CorsRegistration maxAge(long maxAge) {
150
150
* @since 5.3
151
151
*/
152
152
public CorsRegistration combine (CorsConfiguration other ) {
153
- this .config .combine (other );
153
+ this .config = this . config .combine (other );
154
154
return this ;
155
155
}
156
156
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -77,4 +77,24 @@ public void allowCredentials() {
77
77
.as ("Globally origins=\" *\" and allowCredentials=true should be possible" )
78
78
.containsExactly ("*" );
79
79
}
80
+
81
+ @ Test
82
+ void combine () {
83
+ CorsConfiguration otherConfig = new CorsConfiguration ();
84
+ otherConfig .addAllowedOrigin ("http://localhost:3000" );
85
+ otherConfig .addAllowedMethod ("*" );
86
+ otherConfig .applyPermitDefaultValues ();
87
+
88
+ this .registry .addMapping ("/api/**" ).combine (otherConfig );
89
+
90
+ Map <String , CorsConfiguration > configs = this .registry .getCorsConfigurations ();
91
+ assertThat (configs .size ()).isEqualTo (1 );
92
+ CorsConfiguration config = configs .get ("/api/**" );
93
+ assertThat (config .getAllowedOrigins ()).isEqualTo (Collections .singletonList ("http://localhost:3000" ));
94
+ assertThat (config .getAllowedMethods ()).isEqualTo (Collections .singletonList ("*" ));
95
+ assertThat (config .getAllowedHeaders ()).isEqualTo (Collections .singletonList ("*" ));
96
+ assertThat (config .getExposedHeaders ()).isEmpty ();
97
+ assertThat (config .getAllowCredentials ()).isNull ();
98
+ assertThat (config .getMaxAge ()).isEqualTo (Long .valueOf (1800 ));
99
+ }
80
100
}
You can’t perform that action at this time.
0 commit comments