diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index dffdb5c..b6504c4 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -1895,6 +1895,10 @@ public void setSparkConfigUpdated(boolean isSparkConfigUpdated) { new TimeValidator(TimeUnit.SECONDS), "Keepalive time for an idle http worker thread. When the number of workers exceeds min workers, " + "excessive threads are killed after this time interval."), + HIVE_SERVER2_THRIFT_HTTP_REQUEST_HEADER_SIZE("hive.server2.thrift.http.request.header.size", 6*1024, + "Request header size in bytes, when using HTTP transport mode. Jetty defaults used."), + HIVE_SERVER2_THRIFT_HTTP_RESPONSE_HEADER_SIZE("hive.server2.thrift.http.response.header.size", 6*1024, + "Response header size in bytes, when using HTTP transport mode. Jetty defaults used."), // Cookie based authentication when using HTTP Transport HIVE_SERVER2_THRIFT_HTTP_COOKIE_AUTH_ENABLED("hive.server2.thrift.http.cookie.auth.enabled", true, diff --git a/itests/hive-unit/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java b/itests/hive-unit/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java index adb8a71..5230384 100644 --- a/itests/hive-unit/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java +++ b/itests/hive-unit/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java @@ -336,16 +336,15 @@ public String getJdbcURL(String dbName, String sessionConfExt, String hiveConfEx hiveConfExt = (hiveConfExt == null ? "" : hiveConfExt); String krbConfig = ""; if (isUseMiniKdc()) { - krbConfig = ";principal=" + serverPrincipal; + krbConfig = "principal=" + serverPrincipal; } if (isHttpTransportMode()) { - hiveConfExt = "hive.server2.transport.mode=http;hive.server2.thrift.http.path=cliservice;" - + hiveConfExt; + sessionConfExt = "transportMode=http;httpPath=cliservice;" + sessionConfExt; } if (!hiveConfExt.trim().equals("")) { hiveConfExt = "?" + hiveConfExt; } - return getBaseJdbcURL() + dbName + krbConfig + sessionConfExt + hiveConfExt; + return getBaseJdbcURL() + dbName + ";" + krbConfig + ";" + sessionConfExt + hiveConfExt; } /** diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java index 306e3fe..8ba2a12 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java @@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.apache.commons.lang.StringUtils; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; @@ -668,4 +669,58 @@ private void verifyScratchDir(HiveConf conf, FileSystem fs, Path scratchDirPath, fs.getFileStatus(scratchDirPath).getPermission()); } } + + /** + * Test for http header size + * @throws Exception + */ + @Test + public void testHttpHeaderSize() throws Exception { + // Stop HiveServer2 + if (miniHS2.isStarted()) { + miniHS2.stop(); + } + HiveConf conf = new HiveConf(); + conf.set("hive.server2.transport.mode", "http"); + conf.setInt("hive.server2.thrift.http.request.header.size", 1024); + conf.setInt("hive.server2.thrift.http.response.header.size", 1024); + miniHS2 = new MiniHS2(conf); + Map confOverlay = new HashMap(); + miniHS2.start(confOverlay); + + // Username is added to the request header + String userName = StringUtils.leftPad("*", 100); + // This should go fine, since header should be less than the configured header size + try { + hs2Conn = getConnection(miniHS2.getJdbcURL(), userName, "password"); + } catch (Exception e) { + fail("Not expecting exception: " + e); + } + + // This should fail with given HTTP response code 413 in error message, since header is more + // than the configured the header size + userName = StringUtils.leftPad("*", 2000); + try { + hs2Conn = getConnection(miniHS2.getJdbcURL(), userName, "password"); + } catch (Exception e) { + assertTrue("Header exception thrown", e != null); + assertTrue(e.getMessage().contains("HTTP Response code: 413")); + } + + // Stop HiveServer2 to increase header size + if (miniHS2.isStarted()) { + miniHS2.stop(); + } + conf.setInt("hive.server2.thrift.http.request.header.size", 3000); + conf.setInt("hive.server2.thrift.http.response.header.size", 3000); + miniHS2 = new MiniHS2(conf); + miniHS2.start(confOverlay); + + // This should now go fine, since we increased the configured header size + try { + hs2Conn = getConnection(miniHS2.getJdbcURL(), userName, "password"); + } catch (Exception e) { + fail("Not expecting exception: " + e); + } + } } \ No newline at end of file diff --git a/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java b/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java index 046958e..a940bd6 100644 --- a/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java +++ b/service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpCLIService.java @@ -75,6 +75,13 @@ public void run() { // Connector configs SelectChannelConnector connector = new SelectChannelConnector(); + // Configure header size + int requestHeaderSize = + hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_REQUEST_HEADER_SIZE); + int responseHeaderSize = + hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_RESPONSE_HEADER_SIZE); + connector.setRequestHeaderSize(requestHeaderSize); + connector.setResponseHeaderSize(responseHeaderSize); boolean useSsl = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_USE_SSL); String schemeName = useSsl ? "https" : "http"; // Change connector if SSL is used