99import java .util .Map ;
1010import java .util .Objects ;
1111import java .util .Set ;
12+ import java .util .function .Consumer ;
1213import java .util .stream .Collectors ;
1314import java .util .stream .Stream ;
1415import org .springframework .boot .autoconfigure .web .WebProperties ;
1718import org .springframework .context .ApplicationContext ;
1819import org .springframework .core .Ordered ;
1920import org .springframework .core .annotation .Order ;
21+ import org .springframework .http .HttpHeaders ;
2022import org .springframework .http .HttpStatus ;
2123import org .springframework .http .MediaType ;
2224import org .springframework .http .codec .ServerCodecConfigurer ;
@@ -79,7 +81,7 @@ private Mono<ServerResponse> renderDefault(Throwable throwable, ServerRequest re
7981 return ServerResponse
8082 .status (ErrorCode .UNEXPECTED .httpStatus ())
8183 .contentType (MediaType .APPLICATION_JSON )
82- .headers (CorsGlobalConfiguration :: fillCorsHeader )
84+ .headers (headers ( request ) )
8385 .bodyValue (response );
8486 }
8587
@@ -94,7 +96,7 @@ private Mono<ServerResponse> render(CustomBaseException baseException, ServerReq
9496 return ServerResponse
9597 .status (errorCode .httpStatus ())
9698 .contentType (MediaType .APPLICATION_JSON )
97- .headers (CorsGlobalConfiguration :: fillCorsHeader )
99+ .headers (headers ( request ) )
98100 .bodyValue (response );
99101 }
100102
@@ -125,7 +127,7 @@ private Mono<ServerResponse> render(WebExchangeBindException exception, ServerRe
125127 return ServerResponse
126128 .status (HttpStatus .BAD_REQUEST )
127129 .contentType (MediaType .APPLICATION_JSON )
128- .headers (CorsGlobalConfiguration :: fillCorsHeader )
130+ .headers (headers ( request ) )
129131 .bodyValue (response );
130132 }
131133
@@ -140,14 +142,20 @@ private Mono<ServerResponse> render(ResponseStatusException exception, ServerReq
140142 return ServerResponse
141143 .status (exception .getStatusCode ())
142144 .contentType (MediaType .APPLICATION_JSON )
143- .headers (CorsGlobalConfiguration :: fillCorsHeader )
145+ .headers (headers ( request ) )
144146 .bodyValue (response );
145147 }
146148
147149 private String requestId (ServerRequest request ) {
148150 return request .exchange ().getRequest ().getId ();
149151 }
150152
153+ private Consumer <HttpHeaders > headers (ServerRequest request ) {
154+ return (HttpHeaders headers ) -> {
155+ CorsGlobalConfiguration .fillCorsHeader (headers , request .exchange ().getRequest ());
156+ };
157+ }
158+
151159 private BigDecimal currentTimestamp () {
152160 return BigDecimal .valueOf (System .currentTimeMillis ());
153161 }
0 commit comments