Skip to content

Commit 19c2281

Browse files
committed
enable gzip compression [ci skip]
1 parent f4786af commit 19c2281

6 files changed

Lines changed: 28 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ SteVe is designed to run standalone, a java servlet container / web server (e.g.
5757
5858
The basic configuration is defined in [main.properties](src/main/resources/config/prod/main.properties):
5959
- You _must_ change [database configuration](src/main/resources/config/prod/main.properties#L3-L7)
60-
- You _must_ change [the host](src/main/resources/config/prod/main.properties#L16) to the correct IP address of your server. Using `0.0.0.0` to bind to all Interfaces should work as well, but might have security implications
60+
- You _must_ change [the host](src/main/resources/config/prod/main.properties#L16) to the correct IP address of your server
6161
- You _must_ change [web interface credentials](src/main/resources/config/prod/main.properties#L11-L12)
62-
- You _can_ access the application via HTTPS, by [enabling it and setting the keystore properties](src/main/resources/config/prod/main.properties#L25-L28)
62+
- You _can_ access the application via HTTPS, by [enabling it and setting the keystore properties](src/main/resources/config/prod/main.properties#L26-L29)
6363
6464
For advanced configuration please see the [Configuration wiki](https://github.com/RWTH-i5-IDSG/steve/wiki/Configuration)
6565

src/main/java/de/rwth/idsg/steve/Application.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ private static void loadProperties() throws IOException {
6060
Auth.PASSWORD = prop.getString("auth.password");
6161

6262
Jetty.SERVER_HOST = prop.getString("server.host");
63+
Jetty.GZIP_ENABLED = prop.getBoolean("server.gzip.enabled");
64+
6365
Jetty.HTTP_ENABLED = prop.getBoolean("http.enabled");
6466
Jetty.HTTP_PORT = prop.getInt("http.port");
6567
Jetty.HTTPS_ENABLED = prop.getBoolean("https.enabled");

src/main/java/de/rwth/idsg/steve/SteveAppContext.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.eclipse.jetty.server.Handler;
1212
import org.eclipse.jetty.server.handler.HandlerCollection;
1313
import org.eclipse.jetty.server.handler.HandlerList;
14+
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
1415
import org.eclipse.jetty.servlet.FilterHolder;
1516
import org.eclipse.jetty.servlet.ServletHolder;
1617
import org.eclipse.jetty.webapp.WebAppContext;
@@ -49,7 +50,26 @@ public HandlerCollection getHandlers() throws IOException {
4950
return handlerList;
5051
}
5152

52-
private WebAppContext getWebApp() throws IOException {
53+
private Handler getWebApp() throws IOException {
54+
if (SteveConfiguration.Jetty.GZIP_ENABLED) {
55+
return enableGzip(initWebApp());
56+
} else {
57+
return initWebApp();
58+
}
59+
}
60+
61+
/**
62+
* Wraps the whole web app in a gzip handler to make Jetty return compressed content
63+
*
64+
* http://www.eclipse.org/jetty/documentation/current/gzip-filter.html
65+
*/
66+
private Handler enableGzip(WebAppContext ctx) {
67+
GzipHandler gzipHandler = new GzipHandler();
68+
gzipHandler.setHandler(ctx);
69+
return gzipHandler;
70+
}
71+
72+
private WebAppContext initWebApp() throws IOException {
5373
WebAppContext ctx = new WebAppContext();
5474
ctx.setContextPath(SteveConfiguration.CONTEXT_PATH);
5575
ctx.setResourceBase(new ClassPathResource("webapp").getURI().toString());

src/main/java/de/rwth/idsg/steve/SteveConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private SteveConfiguration() { }
3434
*/
3535
public static final class Jetty {
3636
public static String SERVER_HOST;
37+
public static boolean GZIP_ENABLED;
3738

3839
// HTTP
3940
public static boolean HTTP_ENABLED;

src/main/resources/config/dev/main.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ auth.password = 1234
1414
# Jetty configuration
1515
#
1616
server.host = 127.0.0.1
17+
server.gzip.enabled = false
1718

1819
# Jetty HTTP configuration
1920
#

src/main/resources/config/prod/main.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ auth.password = 1234
1414
# Jetty configuration
1515
#
1616
server.host = 127.0.0.1
17+
server.gzip.enabled = true
1718

1819
# Jetty HTTP configuration
1920
#

0 commit comments

Comments
 (0)