9
9
import java .util .Map ;
10
10
import java .util .Objects ;
11
11
import java .util .Set ;
12
+ import java .util .function .Consumer ;
12
13
import java .util .stream .Collectors ;
13
14
import java .util .stream .Stream ;
14
15
import org .springframework .boot .autoconfigure .web .WebProperties ;
17
18
import org .springframework .context .ApplicationContext ;
18
19
import org .springframework .core .Ordered ;
19
20
import org .springframework .core .annotation .Order ;
21
+ import org .springframework .http .HttpHeaders ;
20
22
import org .springframework .http .HttpStatus ;
21
23
import org .springframework .http .MediaType ;
22
24
import org .springframework .http .codec .ServerCodecConfigurer ;
@@ -79,7 +81,7 @@ private Mono<ServerResponse> renderDefault(Throwable throwable, ServerRequest re
79
81
return ServerResponse
80
82
.status (ErrorCode .UNEXPECTED .httpStatus ())
81
83
.contentType (MediaType .APPLICATION_JSON )
82
- .headers (CorsGlobalConfiguration :: fillCorsHeader )
84
+ .headers (headers ( request ) )
83
85
.bodyValue (response );
84
86
}
85
87
@@ -94,7 +96,7 @@ private Mono<ServerResponse> render(CustomBaseException baseException, ServerReq
94
96
return ServerResponse
95
97
.status (errorCode .httpStatus ())
96
98
.contentType (MediaType .APPLICATION_JSON )
97
- .headers (CorsGlobalConfiguration :: fillCorsHeader )
99
+ .headers (headers ( request ) )
98
100
.bodyValue (response );
99
101
}
100
102
@@ -125,7 +127,7 @@ private Mono<ServerResponse> render(WebExchangeBindException exception, ServerRe
125
127
return ServerResponse
126
128
.status (HttpStatus .BAD_REQUEST )
127
129
.contentType (MediaType .APPLICATION_JSON )
128
- .headers (CorsGlobalConfiguration :: fillCorsHeader )
130
+ .headers (headers ( request ) )
129
131
.bodyValue (response );
130
132
}
131
133
@@ -140,14 +142,20 @@ private Mono<ServerResponse> render(ResponseStatusException exception, ServerReq
140
142
return ServerResponse
141
143
.status (exception .getStatusCode ())
142
144
.contentType (MediaType .APPLICATION_JSON )
143
- .headers (CorsGlobalConfiguration :: fillCorsHeader )
145
+ .headers (headers ( request ) )
144
146
.bodyValue (response );
145
147
}
146
148
147
149
private String requestId (ServerRequest request ) {
148
150
return request .exchange ().getRequest ().getId ();
149
151
}
150
152
153
+ private Consumer <HttpHeaders > headers (ServerRequest request ) {
154
+ return (HttpHeaders headers ) -> {
155
+ CorsGlobalConfiguration .fillCorsHeader (headers , request .exchange ().getRequest ());
156
+ };
157
+ }
158
+
151
159
private BigDecimal currentTimestamp () {
152
160
return BigDecimal .valueOf (System .currentTimeMillis ());
153
161
}
0 commit comments