20
20
import static tech .pegasys .teku .infrastructure .json .types .CoreTypes .HTTP_ERROR_RESPONSE_TYPE ;
21
21
22
22
import io .javalin .Javalin ;
23
+ import io .javalin .compression .CompressionStrategy ;
23
24
import io .javalin .config .JavalinConfig ;
24
25
import io .javalin .plugin .bundled .CorsPluginConfig ;
25
26
import io .javalin .util .JavalinLogger ;
@@ -131,14 +132,15 @@ public RestApi build() {
131
132
config -> {
132
133
config .http .defaultContentType = "application/json" ;
133
134
config .showJavalinBanner = false ;
134
- config .compression .gzipOnly ();
135
135
// Work around a bug in Javalin where it decides whether to compress on each call to
136
136
// write which could result in a mix of compressed and uncompressed content
137
137
// and means it doesn't evaluate the length of the response correctly.
138
- config .pvt .compressionStrategy .setMinSizeForCompression (0 );
138
+ CompressionStrategy strategy = CompressionStrategy .GZIP ;
139
+ strategy .setDefaultMinSizeForCompression (0 );
140
+ config .http .customCompression (strategy );
139
141
configureCors (config );
140
142
swaggerBuilder .configureUI (config );
141
- config .jetty .server (this ::createJettyServer );
143
+ config .jetty .modifyServer (this ::modifyJettyServer );
142
144
});
143
145
144
146
if (!hostAllowlist .isEmpty ()) {
@@ -182,16 +184,15 @@ private void addExceptionHandler(
182
184
private void configureCors (final JavalinConfig config ) {
183
185
if (!corsAllowedOrigins .isEmpty ()) {
184
186
if (corsAllowedOrigins .contains ("*" )) {
185
- config .plugins .enableCors (cors -> cors .add (CorsPluginConfig ::anyHost ));
187
+ config .bundledPlugins .enableCors (cors -> cors .addRule (CorsPluginConfig . CorsRule ::anyHost ));
186
188
} else {
187
- config .plugins .enableCors (
188
- cors -> corsAllowedOrigins .forEach (origin -> cors .add (it -> it .allowHost (origin ))));
189
+ config .bundledPlugins .enableCors (
190
+ cors -> corsAllowedOrigins .forEach (origin -> cors .addRule (it -> it .allowHost (origin ))));
189
191
}
190
192
}
191
193
}
192
194
193
- private Server createJettyServer () {
194
- final Server server = new Server ();
195
+ private void modifyJettyServer (final Server server ) {
195
196
final ServerConnector connector ;
196
197
if (maybeKeystorePath .isPresent ()) {
197
198
connector = new ServerConnector (server , getSslContextFactory ());
@@ -201,7 +202,6 @@ private Server createJettyServer() {
201
202
connector .setPort (port );
202
203
connector .setHost (listenAddress );
203
204
server .setConnectors (new Connector [] {connector });
204
-
205
205
maxUrlLength .ifPresent (
206
206
maxLength -> {
207
207
LOG .debug ("Setting Max URL length to {}" , maxLength );
@@ -215,7 +215,6 @@ private Server createJettyServer() {
215
215
}
216
216
});
217
217
JavalinLogger .startupInfo = false ;
218
- return server ;
219
218
}
220
219
221
220
private SslContextFactory .Server getSslContextFactory () {
0 commit comments