@@ -26,24 +26,32 @@ public class HttpConfig {
2626 private final static String MIN_THREADS_CONFIG_KEY = "http.threads.min" ;
2727 private final static String IDLE_TIMEOUT_MILLIS_CONFIG_KEY = "idle.timeout.ms" ;
2828 private final static String STOP_TIMEOUT_MILLIS_CONFIG_KEY = "stop.timeout.ms" ;
29+ private final static String GZIP_ENABLED_KEY = "gzip.enabled" ;
30+ private final static String GZIP_BUFFER_SIZE = "gzip.buffer.size" ;
2931
30- private int port ;
31- private int maxThreads ;
32- private int minThreads ;
33- private int idleTimeout ;
34- private int stopTimeout ;
3532
36- HttpConfig (int port , int minThreads , int maxThreads , int idleTimeout , int stopTimeout ) {
33+ private final int port ;
34+ private final int maxThreads ;
35+ private final int minThreads ;
36+ private final int idleTimeout ;
37+ private final int stopTimeout ;
38+ private final boolean gzipEnabled ;
39+ private final int gzipBufferSize ;
40+
41+ HttpConfig (int port , int minThreads , int maxThreads , int idleTimeout , int stopTimeout , boolean gzipEnabled , int gzipBufferSize ) {
3742 Validate .isTrue (minThreads <= maxThreads , "min threads has to be less than or equal to max threads count" );
3843 Validate .isTrue (port > 0 , "http port should be > 0" );
3944 Validate .isTrue (idleTimeout > 0 , "idle timeout should be > 0" );
4045 Validate .isTrue (stopTimeout > 0 , "stop timeout should be > 0" );
46+ Validate .isTrue (gzipBufferSize > 0 , "gzipbufferSize should be > 0" );
4147
4248 this .port = port ;
4349 this .maxThreads = maxThreads ;
4450 this .minThreads = minThreads ;
4551 this .idleTimeout = idleTimeout ;
4652 this .stopTimeout = stopTimeout ;
53+ this .gzipEnabled = gzipEnabled ;
54+ this .gzipBufferSize = gzipBufferSize ;
4755 }
4856
4957 public int getPort () {
@@ -66,13 +74,23 @@ public int getStopTimeout() {
6674 return stopTimeout ;
6775 }
6876
77+ public boolean isGzipEnabled () {
78+ return gzipEnabled ;
79+ }
80+
81+ public int getGzipBufferSize () {
82+ return gzipBufferSize ;
83+ }
84+
6985 @ SuppressWarnings ("PMD.NPathComplexity" )
7086 public static HttpConfig from (Config config ) {
71- int port = config .hasPath (PORT_CONFIG_KEY ) ? config .getInt (PORT_CONFIG_KEY ) : 9411 ;
72- int maxThreads = config .hasPath (MAX_THREADS_CONFIG_KEY ) ? config .getInt (MAX_THREADS_CONFIG_KEY ) : 16 ;
73- int minThreads = config .hasPath (MIN_THREADS_CONFIG_KEY ) ? config .getInt (MIN_THREADS_CONFIG_KEY ) : 2 ;
74- int idleTimeout = config .hasPath (IDLE_TIMEOUT_MILLIS_CONFIG_KEY ) ? config .getInt (IDLE_TIMEOUT_MILLIS_CONFIG_KEY ) : 60000 ;
75- int stopTimeout = config .hasPath (STOP_TIMEOUT_MILLIS_CONFIG_KEY ) ? config .getInt (STOP_TIMEOUT_MILLIS_CONFIG_KEY ) : 30000 ;
76- return new HttpConfig (port , minThreads , maxThreads , idleTimeout , stopTimeout );
87+ final int port = config .hasPath (PORT_CONFIG_KEY ) ? config .getInt (PORT_CONFIG_KEY ) : 9411 ;
88+ final int maxThreads = config .hasPath (MAX_THREADS_CONFIG_KEY ) ? config .getInt (MAX_THREADS_CONFIG_KEY ) : 16 ;
89+ final int minThreads = config .hasPath (MIN_THREADS_CONFIG_KEY ) ? config .getInt (MIN_THREADS_CONFIG_KEY ) : 2 ;
90+ final int idleTimeout = config .hasPath (IDLE_TIMEOUT_MILLIS_CONFIG_KEY ) ? config .getInt (IDLE_TIMEOUT_MILLIS_CONFIG_KEY ) : 60000 ;
91+ final int stopTimeout = config .hasPath (STOP_TIMEOUT_MILLIS_CONFIG_KEY ) ? config .getInt (STOP_TIMEOUT_MILLIS_CONFIG_KEY ) : 30000 ;
92+ final int gzipBufferSize = config .hasPath (GZIP_BUFFER_SIZE ) ? config .getInt (GZIP_BUFFER_SIZE ) : 16384 ;
93+ final boolean gzipEnabled = config .hasPath (GZIP_ENABLED_KEY ) && config .getBoolean (GZIP_ENABLED_KEY );
94+ return new HttpConfig (port , minThreads , maxThreads , idleTimeout , stopTimeout , gzipEnabled , gzipBufferSize );
7795 }
7896}
0 commit comments