From 7e2731f8de95560d68cc0ef24d17c318c491e8a4 Mon Sep 17 00:00:00 2001 From: Kousuke Saruta Date: Tue, 7 Jul 2020 06:47:28 +0900 Subject: [PATCH] Redirect to / when accessed to /history --- .../apache/spark/deploy/history/HistoryServer.scala | 4 +--- .../spark/deploy/history/HistoryServerSuite.scala | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala b/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala index aa9e9a6dd488..ca21a8056d1b 100644 --- a/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala +++ b/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala @@ -76,9 +76,7 @@ class HistoryServer( // attempt ID (separated by a slash). val parts = Option(req.getPathInfo()).getOrElse("").split("/") if (parts.length < 2) { - res.sendError(HttpServletResponse.SC_BAD_REQUEST, - s"Unexpected path info in request (URI = ${req.getRequestURI()}") - return + res.sendRedirect("/") } val appId = parts(1) diff --git a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala index 8737cd5bb324..db02cf85693a 100644 --- a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala +++ b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala @@ -644,6 +644,19 @@ class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with Matchers val actualContentType = conn.getContentType assert(actualContentType === expectedContentType) } + + test("Redirect to the root page when accessed to /history/") { + val port = server.boundPort + val url = new URL(s"http://localhost:$port/history/") + val conn = url.openConnection().asInstanceOf[HttpURLConnection] + conn.setRequestMethod("GET") + conn.setUseCaches(false) + conn.setDefaultUseCaches(false) + conn.setInstanceFollowRedirects(false) + conn.connect() + assert(conn.getResponseCode === 302) + assert(conn.getHeaderField("Location") === s"http://localhost:$port/") + } } object HistoryServerSuite {