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