Skip to content
Browse files

Added gzip compression of responses returned to user-agents accepting it

Enabled as default, but can be disabled using the "Server Access
Settings" admin page.
  • Loading branch information...
luccioman committed Jun 5, 2018
1 parent a7a4ba3 commit 387d646c0e5da7fe920d900bdeff550b40d4c453
@@ -92,6 +92,11 @@ server.maxTrackingCount = 1000
# maximum number of hosts that are tracked
server.maxTrackingHostCount = 100

# When set to true, enable gzip compression of HTTP responses when the user-agent (browser, another YaCy peer or any kind of client)
# accept gzip encoding (by including gzip in a 'Accept-Encoding' HTTP request header)
# This adds some processing overhead, but reduces the amount of bytes sent over network.
server.response.compress.gzip = true

# Global HTTP Referrer policy delivered by meta tag (see for available policies)
# Can be left empty : the browser should then fallback to the default "no-referrer-when-downgrade" policy
# Be careful, some policies will also affect YaCy internal links : "no-referrer", "same-origin", "origin" and "strict-origin". This can be useful
@@ -208,6 +208,9 @@ <h2>Settings Receipt:</h2>
<td>Shutdown port</td><td> <span class="settingsValue">#[port.shutdown]#</span></td>
::<!-- 37: Compression settings changed -->
<p>Compression settings have been saved.</p>

@@ -258,6 +258,23 @@ else if (!filter.equals("*")){
prop.putHTML("info_filter", filter);
return prop;

/* Compression settings */
if (post.containsKey("serverCompression")) {
// set backlink
prop.put("needsRestart_referer", "Settings_p.html?page=ServerAccess");

final boolean oldValue = env.getConfigBool(SwitchboardConstants.SERVER_RESPONSE_COMPRESS_GZIP,
final boolean newValue = post.containsKey(SwitchboardConstants.SERVER_RESPONSE_COMPRESS_GZIP);
env.setConfig(SwitchboardConstants.SERVER_RESPONSE_COMPRESS_GZIP, newValue);

prop.put("needsRestart", newValue != oldValue);

/* server compression settings saved */
prop.put("info", "37");
return prop;

if (post.containsKey("proxysettings")) {
// set backlink
@@ -66,4 +66,32 @@

<legend>Compression settings</legend>

<div class="form-group">
<div class="col-sm-3">
<div class="checkbox">
<input name="server.response.compress.gzip" id="responseCompressGzip"
type="checkbox" #(server.response.compress.gzip)#::checked#(/server.response.compress.gzip)#
Compress responses with gzip
<div class="col-sm-9" id="responseCompressGzipInfo">
When checked (default), HTTP responses can be compressed using gzip.
The requesting user-agent (a web browser, another YaCy peer or any other tool) uses the header 'Accept-Encoding' to tell whether it accepts gzip compression or not.
This adds some processing overhead, but can significantly reduce the amount of bytes transmitted over the network.
<div class="form-group">
<div class="col-sm-12">
<input type="submit" class="btn btn-primary" name="serverCompression" value="Submit" aria-describedby="submitInfo"/>
<em id="submitInfo">Changes need a server restart.</em>

@@ -135,6 +135,11 @@ else if (page.equals("crawler")) {
// server access filter
prop.putHTML("serverfilter", env.getConfig("serverClient", "*"));

/* gzip compression of HTTP responses */

// server password

@@ -48,6 +48,7 @@
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.InetAccessHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.ssl.SslContextFactory;
@@ -142,6 +143,19 @@ public Jetty9HttpServerImpl(int port) {
sholder.setAsyncSupported(true); // needed for YaCyQoSFilter
//sholder.setInitParameter("welcomeFile", "index.html"); // default is index.html, welcome.html
htrootContext.addServlet(sholder, "/*");

/* Handle gzip compression of responses to user agents accepting it */
final GzipHandler gzipHandler;
if (sb.getConfigBool(SwitchboardConstants.SERVER_RESPONSE_COMPRESS_GZIP,
gzipHandler = new GzipHandler();
* Ensure decompression of requests body is disabled : it is already handled by
* the GZIPRequestWrapper in the YaCyDefaultServlet

// -----------------------------------------------------------------------------
// here we set and map the mandatory servlets, needed for typical YaCy operation
@@ -484,6 +484,12 @@

/** Setting key of the property that collects the names of all servlets that have been used so far. */
public static final String SERVER_SERVLETS_CALLED = "server.servlets.called";

/** Key of the setting controlling whether HTTP responses should be compressed with gzip when the user-agent accepts it (by including gzip in a 'Accept-Encoding' HTTP request header) */
public static final String SERVER_RESPONSE_COMPRESS_GZIP = "server.response.compress.gzip";

/** Default setting value controlling whether HTTP responses should be compressed */
public static final boolean SERVER_RESPONSE_COMPRESS_GZIP_DEFAULT = true;


0 comments on commit 387d646

Please sign in to comment.
You can’t perform that action at this time.