You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by mo...@apache.org on 2017/01/20 19:09:20 UTC
knox git commit: KNOX-855 - Add application/x-javascript mime type to
the list of compressed resources and make it configurable
Repository: knox
Updated Branches:
refs/heads/master f3ffc815d -> 1ad4d0b05
KNOX-855 - Add application/x-javascript mime type to the list of compressed resources and make it configurable
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/1ad4d0b0
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/1ad4d0b0
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/1ad4d0b0
Branch: refs/heads/master
Commit: 1ad4d0b05ec907c8fcebca4eb844bfa68246d2be
Parents: f3ffc81
Author: Sandeep More <mo...@apache.org>
Authored: Fri Jan 20 13:58:35 2017 -0500
Committer: Sandeep More <mo...@apache.org>
Committed: Fri Jan 20 13:58:35 2017 -0500
----------------------------------------------------------------------
.../apache/hadoop/gateway/GatewayServer.java | 8 +++--
.../gateway/config/impl/GatewayConfigImpl.java | 32 ++++++++++++++++++++
.../hadoop/gateway/GatewayGlobalConfigTest.java | 24 +++++++++++++++
.../hadoop/gateway/config/GatewayConfig.java | 6 ++++
.../hadoop/gateway/GatewayTestConfig.java | 9 ++++++
.../hadoop/gateway/GatewayTestConfig.java | 8 +++++
.../hadoop/gateway/GatewayTestConfig.java | 8 +++++
7 files changed, 93 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/1ad4d0b0/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
index 35bb0fe..b5c12d6 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java
@@ -355,8 +355,12 @@ public class GatewayServer {
/* KNOX-732: Handler for GZip compression */
GzipHandler gzipHandler = new GzipHandler();
- gzipHandler.addIncludedMimeTypes("text/html", "text/plain", "text/xml",
- "text/css", "application/javascript", "text/javascript");
+ String[] mimeTypes = {};
+ if (config.getMimeTypesToCompress() != null
+ && !config.getMimeTypesToCompress().isEmpty()) {
+ mimeTypes = (String[]) config.getMimeTypesToCompress().toArray();
+ }
+ gzipHandler.addIncludedMimeTypes(mimeTypes);
gzipHandler.setHandler(correlationHandler);
DefaultTopologyHandler defaultTopoHandler = new DefaultTopologyHandler(
http://git-wip-us.apache.org/repos/asf/knox/blob/1ad4d0b0/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
index 8576c2e..4c94f14 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImpl.java
@@ -147,6 +147,14 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
public static final String WEBSOCKET_ASYNC_WRITE_TIMEOUT = GATEWAY_CONFIG_FILE_PREFIX + ".websocket.async.write.timeout";
public static final String WEBSOCKET_IDLE_TIMEOUT = GATEWAY_CONFIG_FILE_PREFIX + ".websocket.idle.timeout";
+ /**
+ * Comma seperated list of MIME Types to be compressed by Knox on the way out.
+ *
+ * @since 0.12
+ */
+ public static final String MIME_TYPES_TO_COMPRESS = GATEWAY_CONFIG_FILE_PREFIX
+ + ".gzip.compress.mime.types";
+
// These config property names are not inline with the convention of using the
// GATEWAY_CONFIG_FILE_PREFIX as is done by those above. These are left for
// backward compatibility.
@@ -173,6 +181,13 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
public static final int DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT = 60000;
public static final int DEFAULT_WEBSOCKET_IDLE_TIMEOUT = 300000;
+ /**
+ * Default list of MIME Type to be compressed.
+ * @since 0.12
+ */
+ public static final String DEFAULT_MIME_TYPES_TO_COMPRESS = "text/html, text/plain, text/xml, text/css, "
+ + "application/javascript, application/x-javascript, text/javascript";
+
private static List<String> DEFAULT_GLOBAL_RULES_SERVICES;
@@ -758,6 +773,22 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
return getInt( WEBSOCKET_IDLE_TIMEOUT, DEFAULT_WEBSOCKET_IDLE_TIMEOUT);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.hadoop.gateway.config.GatewayConfig#getMimeTypesToCompress()
+ */
+ @Override
+ public List<String> getMimeTypesToCompress() {
+ List<String> mimeTypes = null;
+ String value = get(MIME_TYPES_TO_COMPRESS, DEFAULT_MIME_TYPES_TO_COMPRESS);
+ if (value != null && !value.isEmpty()) {
+ mimeTypes = Arrays.asList(value.trim().split("\\s*,\\s*"));
+ }
+ return mimeTypes;
+ }
+
private static long parseNetworkTimeout(String s ) {
PeriodFormatter f = new PeriodFormatterBuilder()
.appendMinutes().appendSuffix("m"," min")
@@ -767,4 +798,5 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
return p.toStandardDuration().getMillis();
}
+
}
http://git-wip-us.apache.org/repos/asf/knox/blob/1ad4d0b0/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
index 445a119..441a5a6 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/GatewayGlobalConfigTest.java
@@ -25,6 +25,8 @@ import org.junit.Test;
import java.io.File;
import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -187,4 +189,26 @@ public class GatewayGlobalConfigTest {
assertEquals("target/test", config.getGatewayServicesDir());
}
+ /**
+ * Test for the default Mime Types for Gzip compression.
+ *
+ * @since 0.12
+ */
+ @Test
+ public void testDefaultCompressGzipMimeTypes() {
+
+ final List<String> expected = Arrays.asList("text/javascript", "text/html",
+ "text/plain", "text/xml", "text/css", "application/javascript",
+ "application/x-javascript");
+
+ String homeDirName = getHomeDirName("conf-site/conf/gateway-site.xml");
+ System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
+ System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName);
+ GatewayConfig config = new GatewayConfigImpl();
+
+ assertTrue("Default MIME Types for Gzip compression failed to match",
+ config.getMimeTypesToCompress().containsAll(expected));
+
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/knox/blob/1ad4d0b0/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
index 1d877fd..ca86e44 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/config/GatewayConfig.java
@@ -214,4 +214,10 @@ public interface GatewayConfig {
int getGraphiteReportingFrequency();
+ /**
+ * List of MIME Type to be compressed.
+ * @since 0.12
+ */
+ List<String> getMimeTypesToCompress();
+
}
http://git-wip-us.apache.org/repos/asf/knox/blob/1ad4d0b0/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index 5c633d0..7c72541 100644
--- a/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test-release/webhdfs-kerb-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -424,6 +424,7 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig {
public int getWebsocketIdleTimeout() {
return DEFAULT_WEBSOCKET_IDLE_TIMEOUT;
}
+
@Override
public boolean isMetricsEnabled() {
@@ -454,4 +455,12 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig {
public int getGraphiteReportingFrequency() {
return 0;
}
+
+ /* (non-Javadoc)
+ * @see org.apache.hadoop.gateway.config.GatewayConfig#getMimeTypesToCompress()
+ */
+ @Override
+ public List<String> getMimeTypesToCompress() {
+ return new ArrayList<String>();
+ }
}
http://git-wip-us.apache.org/repos/asf/knox/blob/1ad4d0b0/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index 5c633d0..22f65cc 100644
--- a/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test-release/webhdfs-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -425,6 +425,14 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig {
return DEFAULT_WEBSOCKET_IDLE_TIMEOUT;
}
+ /* (non-Javadoc)
+ * @see org.apache.hadoop.gateway.config.GatewayConfig#getMimeTypesToCompress()
+ */
+ @Override
+ public List<String> getMimeTypesToCompress() {
+ return new ArrayList<String>();
+ }
+
@Override
public boolean isMetricsEnabled() {
return false;
http://git-wip-us.apache.org/repos/asf/knox/blob/1ad4d0b0/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index f5c7149..25a09f7 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -512,4 +512,12 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig {
public int getGraphiteReportingFrequency() {
return 0;
}
+
+ /* (non-Javadoc)
+ * @see org.apache.hadoop.gateway.config.GatewayConfig#getMimeTypesToCompress()
+ */
+ @Override
+ public List<String> getMimeTypesToCompress() {
+ return new ArrayList<String>();
+ }
}