knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-932 - Option to remove the server-name from HTTP-header response (Lawrence McCay IV via lmccay)
Date Fri, 09 Jun 2017 03:24:03 GMT
Repository: knox
Updated Branches:
  refs/heads/master 0064e33d6 -> f4ccdfd69


KNOX-932 - Option to remove the server-name from HTTP-header response (Lawrence McCay IV via
lmccay)

Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/f4ccdfd6
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/f4ccdfd6
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/f4ccdfd6

Branch: refs/heads/master
Commit: f4ccdfd696bca10c73e7a7e336d9e72d4db423b5
Parents: 0064e33
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Thu Jun 8 23:23:42 2017 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Thu Jun 8 23:23:42 2017 -0400

----------------------------------------------------------------------
 .../org/apache/hadoop/gateway/GatewayServer.java     |  8 ++++++--
 .../gateway/config/impl/GatewayConfigImpl.java       |  6 ++++++
 .../gateway/config/impl/GatewayConfigImplTest.java   | 15 ++++++++++++++-
 .../apache/hadoop/gateway/config/GatewayConfig.java  |  8 ++++++--
 .../org/apache/hadoop/gateway/GatewayTestConfig.java |  4 ++++
 5 files changed, 36 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/f4ccdfd6/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 a379af5..2fa803f 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
@@ -54,6 +54,7 @@ import org.apache.hadoop.gateway.util.Urls;
 import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.hadoop.gateway.websockets.GatewayWebsocketHandler;
 import org.apache.log4j.PropertyConfigurator;
+import org.eclipse.jetty.server.ConnectionFactory;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.HttpConfiguration;
 import org.eclipse.jetty.server.HttpConnectionFactory;
@@ -310,7 +311,11 @@ public class GatewayServer {
         NetworkConnector connector = (NetworkConnector) server.jetty
             .getConnectors()[i];
         if (connector != null) {
-
+          for(ConnectionFactory x  : connector.getConnectionFactories()) {
+            if(x instanceof HttpConnectionFactory) {
+                ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(config.isGatewayServerHeaderEnabled());
+            }
+          }
           if (connector.getName() == null) {
             log.startedGateway(
                 connector != null ? connector.getLocalPort() : -1);
@@ -318,7 +323,6 @@ public class GatewayServer {
             log.startedGateway(connector != null ? connector.getName() : "",
                 connector != null ? connector.getLocalPort() : -1);
           }
-
         }
       }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f4ccdfd6/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 7089e07..79140e0 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
@@ -210,6 +210,7 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   private static final String CRYPTO_SALTSIZE = GATEWAY_CONFIG_FILE_PREFIX + ".crypto.salt.size";
   private static final String CRYPTO_ITERATION_COUNT = GATEWAY_CONFIG_FILE_PREFIX + ".crypto.iteration.count";
   private static final String CRYPTO_KEY_LENGTH = GATEWAY_CONFIG_FILE_PREFIX + ".crypto.key.length";
+  public static final String SERVER_HEADER_ENABLED = GATEWAY_CONFIG_FILE_PREFIX + ".server.header.enabled";
 
   private static List<String> DEFAULT_GLOBAL_RULES_SERVICES;
 
@@ -906,4 +907,9 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   public String getKeyLength() {
 	return getVar(CRYPTO_KEY_LENGTH, null);
   }
+
+  @Override
+  public boolean isGatewayServerHeaderEnabled() {
+    return Boolean.parseBoolean(getVar(SERVER_HEADER_ENABLED, "true"));
+  }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/f4ccdfd6/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.java
b/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.java
index 24b45b1..8c8835c 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/config/impl/GatewayConfigImplTest.java
@@ -190,7 +190,7 @@ public class GatewayConfigImplTest {
     assertThat(config.getGraphiteHost(), is("localhost"));
     assertThat(config.getGraphitePort(), is(32772));
   }
-
+  
   @Test( timeout = TestUtils.SHORT_TIMEOUT )
   public void testGatewayIdleTimeout() {
     GatewayConfigImpl config = new GatewayConfigImpl();
@@ -203,5 +203,18 @@ public class GatewayConfigImplTest {
     idleTimeout = config.getGatewayIdleTimeout();
     assertThat( idleTimeout, is(15000L));
   }
+  
+  @Test( timeout = TestUtils.SHORT_TIMEOUT )
+  public void testGatewayServerHeaderEnabled() {
+    GatewayConfigImpl config = new GatewayConfigImpl();
+    boolean serverHeaderEnabled = true;
+    
+    serverHeaderEnabled = config.isGatewayServerHeaderEnabled();
+    assertThat( serverHeaderEnabled, is(true));
+
+    config.set( GatewayConfigImpl.SERVER_HEADER_ENABLED, "false");
+    serverHeaderEnabled = config.isGatewayServerHeaderEnabled();
+    assertThat( serverHeaderEnabled, is(false));
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/f4ccdfd6/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 ed868b1..506c31e 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
@@ -287,10 +287,14 @@ public interface GatewayConfig {
   Map<String, Integer> getGatewayPortMappings();
 
   /**
-   * Is the Port Mapping feature on ?
+   * Is the Port Mapping feature on
    * @return
    */
   boolean isGatewayPortMappingEnabled();
 
-
+  /**
+   * Is the Server header suppressed
+   * @return
+   */
+  boolean isGatewayServerHeaderEnabled();
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/f4ccdfd6/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
index eb692bc..dde5908 100644
--- a/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
+++ b/gateway-test-release-utils/src/main/java/org/apache/hadoop/gateway/GatewayTestConfig.java
@@ -603,4 +603,8 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig
{
     return isTopologyPortMappingEnabled;
   }
 
+  @Override
+  public boolean isGatewayServerHeaderEnabled() {
+	return false;
+  }
 }


Mime
View raw message